| Getting Started | ![]() |
break
The break statement lets you exit early from a for loop or while loop. In nested loops, break exits from the innermost loop only.
Here is an improvement on the example from the previous section. Why is this use of break a good idea?
a = 0; fa = -Inf; b = 3; fb = Inf; while b-a > eps*b x = (a+b)/2; fx = x^3-2*x-5; if fx == 0 break elseif sign(fx) == sign(fa) a = x; fa = fx; else b = x; fb = fx; end end x
| continue | try - catch | ![]() |
© 1994-2005 The MathWorks, Inc.