This example is from Bruce Eckel, Thinking in
Java p. 138.
The output is:
i= 0
k = 0
k = 1
k = 2
k = 3
continue inner
i= 1
k = 0
k = 1
k = 2
k = 3
continue inner
i= 2
continue
i= 3
break
i= 4
k = 0
k = 1
k = 2
k = 3
continue inner
i= 5
k = 0
k = 1
k = 2
k = 3
continue inner
i= 6
k = 0
k = 1
k = 2
k = 3
continue inner
i= 7
continue outer
i= 8
break outer
My confusion is why is there a difference in behavior between
loop #2 and loop #3 when a labeled continue is used?
After leaving loop #3 via the continue inner statement, the loop #3 always starts anew whenever it is revisited (as can be seen with k= 0...3). However this same behavior is not seen in loop #2 when program flow leaves the loop via the continue outer statement. The loop does not start anew the next time. Why?
[ Jess added
UBB [CODE] tags, adjusted white space and disabled smilies ]
[ August 29, 2002: Message edited by: Jessica Sant ]