Traditional wisdom has it that goto is extremely wicked. goto is a reserved word in Java, but it is also illegal. But you need it in a few situations, e.g. to jump to the end of a loop and to jump out of a loop.
continue jumps to the end of the current loop (for or while) and goes around again. In contrast break jumps just past the end of the current loop.
If you use a name after the continue e.g. continue outer; it will jump to the end of the loop named outer: (Look for the label at the top of the loop). If you use a name after the break e.g. break outer; it will jump just past the end of the loop named outer:.
You can jump out of nested loops, but you cannot jump in.
The equivalent feature in a switch statement is break.
You can also use break to leap out of a loop entirely.
Be careful when using continue or break to make sure There is no intervening loop or switch inside the one you want to leap out of.
This page is posted
Optional Replicator mirror
Please read the feedback from other visitors, or send your own feedback about the site.
Contact Roedy. Please feel free to link to this page without explicit permission.
Your face IP:[18.104.22.168]
You are visitor number|