'how do I break the outermost for-loop in a switch in a nested for-loop? [duplicate]

I have two for loops and in the innermost for loop I have a switch. And is it possible that in one case of the switch, the entire trip through the outermost loop should be aborted, so that one goes over to the next value automatically, for example, the outermost loop is at the 1 pass and with the command in the switch, I come to the second pass, is that possible?

With break it will not work, do you have any ideas?

example:

for (){
  for (){
    switch(){
    case 1:
    //now I want to break here the inner loop, to go 1 step further, by the outer loop
    }
  }
  // do something not wanted in case 1
}


Solution 1:[1]

As I am not certain exactly what you consider first I labelled both. The following will continue the next iteration of the outer loop.

outer:
for () {
   inner:
   for () {
       switch() {
       case 1:
         continue outer;  // or break inner;
       }
   }
}

Note that the in the case of break inner;, the label must be still be included since break; would simply break out of the switch block.

Solution 2:[2]

you can use label:

first :for (int i = 0; i < args.length; i++) {
    second : for (int j = 0; j < args.length; j++) {
        switch (j) {
        case 1:

            break second;// use this for breaking the second loop or use 
            //continue first; // to break the second and continue the first
        default:
            break;
        }
    }
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2