|
Breaking Out of Loops
A Programming Pattern |
|
Prof. David Bernstein
|
| Computer Science Department |
| bernstdh@jmu.edu |
break statement
that causes control to be transferred to the end
of the immediately enclosing loop
break statement sparingly
(if at all)
break Statement
break statements can be hard to seebreak statements are often
in if statements in loopsbreak statements are often in nested loops
boolean expression
break Statements:
break statement)if statement
(e.g., replace if (data[i] < 0) done = true;
with done = (data[i] < 0);)