Break nested loop

matlab

Solution

BREAK terminates the execution of a loop, so if you have a nested loop, `break` will only quit the innermost loop, and the program will continue running.

If you want the entire function to be terminated, you need to use RETURN. Please note that at the moment `return` is called, all the requested output arguments must be assigned to some value, otherwise the code will throw an error.

Problem

I have three nested loop in Matlab and in each loop, I have an "if" that check a flag. If it was OK, the the algorithm proceeds, otherwise, I want that the program should be terminated. Here is my codes, I think something is wrong! ``` [A] = finction (...,...,...) for i = 1:100 for j = 1:100 for k = 1:30 some operation which its results is a flag if flag==1 % its initial value is 0 break end; end; end; end; ``` Where is should put that break in order I break the rest of the computations?

Original source