Hot Posts

Break, Continue and Labels

Break and Continue

  • break and continue are designed to stop either the entire loop (break) or just the current iteration (continue).

continue

  • must be inside the loop
  • causes the current iteration of the inner most loop to cease and the next to start

break

  •  a break without a label breaks the current loop. No more iterations.

Labelled Statements

  • normally used with loops, but not always
  • often used with break and continue
  • the label is placed just before the statement it labels and ends with a colon. e.g. LABEL:.

break label;

  • can ONLY be used to label a loop or a block. If used to label a statement the code will not compile.
  • the flow will exit out of the loop labeled by the label in the break statement.
  • if this happens within a try…catch then the control will go to the finally statement.

continue label;

  • the flow will continue with the next iteration of the loop labelled in the continue statement.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: