Next: notes Up: MacAnova Help File Previous: ndims()   Contents

next

Usage:
for(i,run(n)){if(x[i] < 0){next} .... }
for(i,run(n)){for(j,run(m)){if(x[i,j] < 0){next 2} .... }}



Keywords: control, syntax
'next', when used in a 'while' or 'for' loop, skips to just before the
'}' that terminates the loop, ignoring any intervening commands.
Execution resumes immediately before the '}'.

'next n', where n is a positive integer, skips to the end of the n-th
enclosing loop.  For example, 'next 1' is equivalent to 'next' and will
skip to the end of the current loop; 'next 2' will exit the current loop
and skip to the end of the loop enclosing it; and so on.  n must be a
literal integer ('1', '2', ...) and not a variable with integer value.

It is an error to use 'next' outside of a loop or to use 'next n' when
not enclosed in at least n loops.

In an evaluated string or out-of-line macro, 'next' can be used only to
skip to the end of a loop that started in the macro or evaluated string.
It is an error to try to skip to the end of a loop that started outside
the macro or evaluated string.  See evaluate() and 'macros'.

Using 'next' in an in-line macro to skip to the end a loop that started
outside the macro will work, but is a bad programming practice.

Examples:
  for(i,run(100)){... compute x ...;if(x<0){next};... do something ...;}
Whenever the computed x becomes negative, no further computation is done
for that value of i.

  for(i,run(10)){for(j,run(5)){...;if(x<0){next 2}; ... }; ...}
Whenever x becomes negative on any pass through the j loop, that loop is
terminated and execution resumes before the '}' which ends the i loop.

See also topics 'if', 'for', 'while', 'break', 'breakall', batch().


Gary Oehlert 2003-01-15