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).
- must be inside the loop
- causes the current iteration of the inner most loop to cease and the next to start
- a break without a label breaks the current loop. No more iterations.
- 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:.
- 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.
- the flow will continue with the next iteration of the loop labelled in the continue statement.