
Flow Control
break
The bre ak 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 im provement 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 > ep s*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
Error Control – try, catch
This section covers those MATLAB functions that provide error handling
control.
try
The general form of a try-catch statement sequence is
try
statement
...
statement
catch
statement
...
statement
end
4-7
Komentarze do niniejszej Instrukcji