The next Statement
next if condition
next name if condition
next integer if condition
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 to-clause, while-clause, and/or until-clause 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 multi-level next statement is a next followed by either the name of a for-loop 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 for-loop 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 multi-level next in the two-variable form of for-in loop can refer to either of the two variables.
When a multi-level 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 for-loop 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: Multi-level next statements are not currently supported in 2-D input in the Standard interface.
Print all the non-string entries in a list:
L := [1, 2, "abc", "a", 7.0, infinity]:
for x in L do
if type(x, 'string') then
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
if i = j then
next i; # alternatively, next 2;
Print the rows of a Matrix, skipping any rows containing a zero.
M, N := 4, 3:
A := LinearAlgebra:-RandomMatrix(M,N):
A[2,2] := 0:
for row to M do
for col to N do
next row if A[row,col] = 0;
The multi-level and conditional next statements are new in Maple 2020.1
Download Help Document
What kind of issue would you like to report? (Optional)