This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

break statement.  RSS feed

 
Anna s Iyer
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why did break statement not going to the Inner loop by specifying the label Inner in the following code?.
class forloop {
public static void main (String args[]) {
//int j,k;
Outer: for(int i=0; i < 2; i++) {
System.out.println("i out "+i);
Inner:for(int j=0; j < 3; j++) {
if (i==j) {
break Inner; //Does not go to the Inner label and increments j
}
System.out.println("i is " +i +" j is " +j);
}
}
}
}
Thanks,
Iyer.
 
Shankar G
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Break statement would try to break out of the enclosing loop while continue statement would try to continue the enclosing loop with the next loop-variable value -- if your intention is to continue the loop, use continue <label> instead.
Hope this helps.
- Shankar.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!