View Single Post
  #2 (permalink)  
Old 01-30-2008, 12:02 AM
tim's Avatar
tim tim is offline
Senior Member
 
Join Date: Dec 2007
Location: South Africa
Posts: 334
tim is on a distinguished road
Example similar to the goto statement in other languages
Hello javaplus

This is the best that I can do now:
Code:
int i = 3, j = 2, k = 4; boolean switching = true; gohere:{ 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; break gohere; // 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; } }
This gives the output:
Code:
breaking
Note that there was no oopses.

I hope that helped.
__________________
If your ship has not come in yet then build a lighthouse.
Reply With Quote