How to continue outer loop in C#

2 Answers

0 votes
using System;

class Program
{
    static void Main()
    {
        for (int outer = 0; outer < 4; outer++) {
            for (int inner = 0; inner < 3; inner++) {
                if (inner == 2) {
                    goto ContinueOuter; // Jump to the label to continue the outer loop
                }
                Console.WriteLine($"Outer: {outer}, Inner: {inner}");
            }

        ContinueOuter:
            // Label to jump to
            Console.WriteLine($"continue_outer: {outer}");
        }
    }
}


/*
run:

Outer: 0, Inner: 0
Outer: 0, Inner: 1
continue_outer: 0
Outer: 1, Inner: 0
Outer: 1, Inner: 1
continue_outer: 1
Outer: 2, Inner: 0
Outer: 2, Inner: 1
continue_outer: 2
Outer: 3, Inner: 0
Outer: 3, Inner: 1
continue_outer: 3

*/

 



answered Apr 24, 2025 by avibootz
0 votes
using System;

public class Program
{
    public static void Main(string[] args)
    {
        int[] arr1 = {4, 5, 1, 1, 6, 7, 0, 1, 1, 1, 8};
        int[] arr2 = {9, 1, 2};

        int nval2 = 0;
        foreach (int val1 in arr1) {
            foreach (int val2 in arr2) {
                nval2 = val2;
                if (val2 == val1) {
                    break;
                }
            }
            if (nval2 == val1) {
                continue;
            }
                
            Console.Write(val1 + " ");
        }
    }
}


/*
run:

4 5 6 7 0 8 

*/

 



answered Apr 24, 2025 by avibootz

Related questions

3 answers 103 views
103 views asked Apr 28, 2025 by avibootz
1 answer 80 views
1 answer 111 views
111 views asked Apr 25, 2025 by avibootz
3 answers 183 views
2 answers 118 views
1 answer 154 views
154 views asked Apr 24, 2025 by avibootz
...