Click to See Complete Forum and Search --> : labeled continue and break
Darkwraith
May 20th, 2004, 05:13 PM
I am a beginner in Java so maybe I got this wrong, but do the labeled continue and break statements act like the goto of so many other programming languages?
If it does, should we ever use these labeled forms?
Dillinger4
May 21st, 2004, 02:04 PM
The continue and break statements are normally refered to as transfer statments with the others being control if, if else and iteration for, while. The break statement serves to break loops and continue statements serve to continue execution by passing the point after the continue and going back to the begining of the loop. Goto should never really be used in any modern programming lauguage since it leads to what some people call Spaghetti code.
CornedBee
May 23rd, 2004, 03:57 AM
Labeled break and continue serve to break out of nested loops, like in
outer:
for(int i = 0; i < 100; ++i) {
for(int j = 0; j <= i; ++j) {
break outer;
}
}
Whether it makes sense is open for debate.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.