
Calling Sequence


next
next name
next integer
next if condition
next name if condition
next integer if condition


Description


•

When a simple next statement is executed, execution of the current iteration of the innermost repetition (for/while/do) statement is terminated and the next iteration, if any, begins.


Beginning the next iteration implies that the control variable is incremented, and then the tests for termination (as specified by the toclause, whileclause, and/or untilclause if present) are applied before proceeding. Thus, an exit from the loop may occur as a result of next statement.


In effect, execution skips the remainder of the loop's body, and resumes just before the terminating end do or until clause of the repetition statement.

•

A multilevel next statement is a next followed by either the name of a forloop control variable, or a positive integer.

•

If next is followed by the name of a variable, then execution continues with the next iteration of the innermost forloop that has that variable as its control variable. Note that the variable is taken literally. It is not evaluated.

•

If next is followed by an integer N, then execution continues with the next iteration of the Nth innermost repetition statement. The statement next 1 is equivalent to just next.

•

A multilevel next in the twovariable form of forin loop can refer to either of the two variables.

•

When a multilevel next is used within a loop expression, the referenced enclosing for must appear within the same expression. One cannot force the next iteration of an enclosing expression.

•

It is an error if a next is appears in a context other than within a repetition statement, or if a qualifed next appears there is no enclosing forloop using the specified control variable or there are fewer than N enclosing repetition statements.

•

A next statement may optionally be followed by the keyword if and a condition to be evaluated. The next statement is executed if and only if the condition evaluates to true.


The statement next if condition is a convenient shorthand for, and semantically equivalent to, if condition then next; end if.

•

In Maple V Release 5.1 and earlier, next was just a Maple symbol. In Maple 6 and later, next is a keyword in the Maple language.

Note: Multilevel next statements are not currently supported in 2D input in the Standard interface.


Examples


Print all the nonstring entries in a list:
>

L := [1, 2, "abc", "a", 7.0, infinity]:

>

for x in L do
if type(x, 'string') then
next;
end if;
print(x);
end do;

Print ordered pairs [1,1], [1,2], ..., [4,4], omitting any [i,j] where j > i.
>

for i to 4 do
for j to 4 do
print([i,j]);
if i = j then
next i; # alternatively, next 2;
end if;
end do;
end do:

$\left[{1}{\,}{1}\right]$
 
$\left[{2}{\,}{1}\right]$
 
$\left[{2}{\,}{2}\right]$
 
$\left[{3}{\,}{1}\right]$
 
$\left[{3}{\,}{2}\right]$
 
$\left[{3}{\,}{3}\right]$
 
$\left[{4}{\,}{1}\right]$
 
$\left[{4}{\,}{2}\right]$
 
$\left[{4}{\,}{3}\right]$
 
$\left[{4}{\,}{4}\right]$
 (2) 
Print the rows of a Matrix, skipping any rows containing a zero.
>

A := LinearAlgebra:RandomMatrix(M,N):

$\left[\begin{array}{ccc}{\mathrm{32}}& {8}& {44}\\ {\mathrm{74}}& {0}& {92}\\ {\mathrm{4}}& {99}& {\mathrm{31}}\\ {27}& {29}& {67}\end{array}\right]$
 (3) 
>

for row to M do
for col to N do
next row if A[row,col] = 0;
end do;
print(A[row]);
end do:

$\left[\begin{array}{ccc}{\mathrm{32}}& {8}& {44}\end{array}\right]$
 
$\left[\begin{array}{ccc}{\mathrm{4}}& {99}& {\mathrm{31}}\end{array}\right]$
 
$\left[\begin{array}{ccc}{27}& {29}& {67}\end{array}\right]$
 (4) 


Compatibility


•

The multilevel and conditional next statements are new in Maple 2020.1



