• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

break , continue with label

 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I understand use of break & continue keywords :
break : it stops the control & moves it to out of loop .
continue : it stops the control & moves the control to the next iteration .

But I am confuse when we used this two with label . Can any body explain with short example .

I hope the question is clear .

Thanks a lot .
 
Jay Ashar
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Break statement when used with label terminates the labelled statement and flow of control is transferred to statement following labelled statement.
continue-label statement is used to skip over the current iteration, usually used with nested loops. Continue statement will skip the current iteration but if you have nested loop and you want to skip the iteration for outer loop you can use continue with label.
 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Both will do their work same as they do in case of label also , just one difference is that , they use loop ( for moving control ) which we mentioned by label .



Like in this case break is moving control out of inner loop .

And in this case , we specified which for loop it should use for moving control by label .

Is everything is right ?

Thanks .
 
Jay Pawar
Ranch Hand
Posts: 411
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes... break with label a will terminate the loop with index i.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic