Only 44 hours left in the trailboss' kickstarter!

New rewards and stretch goals. CLICK HERE!



Win a copy of Murach's Python Programming this week in the Jython/Python 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!