' break
' statement
The break
statement lets you exit early from a for or while loop. In nested
loops,
break
exits from the innermost loop only.
Example 1:
for
i = length(x)
% check for positive y
if
y(x) > 0
% terminate loop execution
break
end
% follow your code
a = a + y(x);
...
end
Example 2:
x = sin(sqrt(variable));
while
1
n = input('Enter
number of loops: ')
if
n <= 0
% terminate loop execution
break
end
for
i = 1 : n
% follow your code
x = x + 20;
...
end
end


|
|