break - Maple Help

Online Help

All Products    Maple    MapleSim


The break Statement

 

Calling Sequence

Description

Examples

Compatibility

Calling Sequence

break

break name

break N

break if condition

break name if condition

break N if condition

Description

• 

When a simple break statement is executed, the result is to exit from the innermost repetition (for/while/do) statement within which it occurs.

• 

After exit, execution proceeds with the first statement following the repetition statement.

• 

A multi-level break statement is a break followed by either the name of a for-loop control variable, or a positive integer.

• 

If break is followed by the name of a variable, then execution exits from the innermost for-loop that has that variable as its control variable. Note that the variable is taken literally. It is not evaluated.

• 

If break is followed by an integer N, then execution exits the Nth innermost repetition statement. The statement break 1 is equivalent to just break.

• 

A multi-level break in the two-variable form of for-in loop can refer to either of the two variables.

• 

When a multi-level break is used within a loop expression, the referenced enclosing for must appear within the same expression. One cannot terminate iteration of an enclosing expression.

• 

It is an error if a break appears in a context other than within a repetition statement, or if a qualified break appears where there is no enclosing for-loop using the specified control variable, or there are fewer than N enclosing repetition statements.

• 

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

  

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

• 

break is a keyword in the Maple language.

Examples

Find and print the first string in a list:

L1,2,abc,a,7.0,:

forxinLdoiftypex,stringthenprintx;breakendifenddo:

abc

(1)

Print ordered pairs [1,1], [1,2], ..., [4,4], stopping after [2,3]:

forito4doforjto4doprinti,j;ifi=2andj=3thenbreakendifenddoenddo:

1,1

1,2

1,3

1,4

2,1

2,2

2,3

(2)

Print each row of a Matrix, stopping after the first row containing a zero.

M,N4,3:

ALinearAlgebra:-RandomMatrixM,N:

A2,20:

printA

−32844−74092−499−31272967

(3)

forrowtoMdoprintArow;forcoltoNdoifArow,col=0thenbreakendifenddoenddo:

−32844

−74092

(4)

Compatibility

• 

The multi-level and conditional break statements are new in Maple 2021.

• 

The The break Statement command was updated in Maple 2021.

See Also

do

Maple keywords

next