Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

break statement

 
kevin schmidt
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic