Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

break and contine in blocks

 
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.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic