Next: breakif() Up: MacAnova Help File Previous: break   Contents


for(i,run(n)){if(x[i] < 0){breakall} .... }
for(i,run(n)){for(j,run(m)){if(x[i,j] < 0){breakall}}}

Keywords: control, syntax
'breakall' is used in 'while' and 'for' loops to exit prematurely from
any and all "enclosing" 'while' or 'for' loops.  Execution resumes
immediately after the '}' terminating the most inclusive 'while' or
'for' loop currently in effect.

'breakall' should normally not be used inside a macro, since if such a
macro were invoked in a loop at the prompt level, 'breakall' would exit
from that loop as well as any loops in the macro.  This would seldom be
what you want.  Instead, use 'break n', where n is a positive integer
specifying the number of loops to exit.  See 'break'.

It is an error to use 'breakall' outside of a loop.

In an evaluated string or out-of-line macro, 'breakall' will exit the
outermost loop that started inside the evaluated string or macro.  It is
an error if there is no such enclosing loop.  See evaluate() and

In an in-line macro (the default), 'breakall' will exit not only loops
which start in the macro, but also any loops which enclose the macro.
If this is not what is wanted (and it usually wouldn't be), use 'break
n', where n is the number of loops enclosing 'break' in the macro.
Use 'return' to exit from a macro prematurely.

  Cmd> for(i,run(m)){
          for(j,run(n)){... compute x ...;if(x<0){breakall};}}

If x ever becomes negative, both 'for' loops are immediately terminated.
Using 'break' instead of breakall would mean that only the inner loop
(for(j,run(n)){...}) would be terminated.

See also topics 'if', 'for', 'while', 'break', 'next', 'return'.

Gary Oehlert 2003-01-15