This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

break and contine in blocks  RSS feed

 
Lokanadham Nalla
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
--------------------------------------
1)

block:
{
break block;
}
--------------------------------------
2)

block:
{
continue block;
}
--------------------------------------
1 is valid and 2 is invalid,

Can we apply break to block statements? Is it valid?
 
abhishek chauhan
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
a label break statement can be used to terminate any labeled statements that contains break statement .. this could be a normal block also where as the continue statement can only be applied to the loops
 
Alangudi Balaji Navaneethan
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
break statement is used in loops and in switch statements normally.

When used in switch case, control come out of the switch after executing break statement. Continue statement cannot be used with swith ... case statements.

continue statement takes the control to the test portion of the loop after executing itself. Then the loop will continue its body or not based on the test result.
 
Arulkumar Gopalan
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
continue can indirectly act as a break also... check the code below.

 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!