I have 3 switch block that are nested. From inner most, I have a case from which I want to break from all the switches.
How this can be done.
Thanks a lot for looking into this.
Printable View
I have 3 switch block that are nested. From inner most, I have a case from which I want to break from all the switches.
How this can be done.
Thanks a lot for looking into this.
Hello javaplus
This is the best that I can do now:
This gives the output:Code:int i = 3, j = 2, k = 4;
boolean switching = true;
[B]gohere:[/B]{
if (switching) switch (i){
case 0:
System.out.println("impossible :)");
break;
case 3:
switch (j){
case 2:
switch (k){
case 4:
System.out.println("breaking");
i = 4;
switching = false;
[B]break gohere;[/B] // similar to a while loop, but execution skips to the label immediately.
}
break;
}
System.out.println("oops)");
break;
case 4:
System.out.println("oops)");
break;
}
}
Note that there was no oopses. :DCode:breaking
I hope that helped. ;)
Thanks Tim. You used labels. I have read somewhere that it is not recommended to use labels in Java. But if there is an absolute need, then one may use them. I think its the only solution to my problem - so Ill use it.
Tanks again.
Sure, in absolute cases it's acceptable. But as in Java, there are many ways to perform a task... maybe there was another way to write your logic? I don't know, I'm just throwing that out there...