This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes break statement Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "break statement" Watch "break statement" New topic
Author

break statement

kevin schmidt
Ranch Hand

Joined: Aug 24, 2001
Posts: 85
Hi.
If you have nested for loops, and you have a break statement inside the deepest nested for loop, does the break statement quit that for statement and continue with the rest of the program, or does it kick out of all for loops? Hope this is clear. TIA.
Kevin
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
From the way that you phrase this I am assuming that you mean a break with no label. In that case only the for loop that contains the break is abruptly completed and execution continues in the next outermost for loop.

From the JLS 14.14 The break Statement
A break statement with no label attempts to transfer control to the innermost enclosing switch, while, do, or for statement of the immediately enclosing method or initializer block; this statement, which is called the break target, then immediately completes normally.


"JavaRanch, where the deer and the Certified play" - David O'Meara
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: break statement
 
Similar Threads
Doubts about break
Exiting loops when criteria found?
break vs continue
Some problem
break , continue with label