initial value in for loop - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : System : Error Message Guide : initial value in for loop

Error:    ...initial value in for loop must be numeric or character

...increment of for loop must be numeric

...increment when looping over characters must be an integer

...final value in for loop must have same type as initial

 

Description

Examples

Description

The error messages related to loops indicate that elements must be numeric, character, or integer.

Examples

Initial value

forxfrommyvariableto5whiletruedoprintxenddo;

Error, initial value in for loop must be numeric or character

If the final value is numeric, ensure that the initial value is numeric, for example, 1.

forxto5whiletruedoprintxenddo;

1

2

3

4

5

(2.1)

forxfrommyvariabletocwhiletruedoprintxenddo;

Error, initial value in for loop must be numeric or character

If the final value is a character, ensure that initial value is also a character.

forxfromatocwhiletruedoprintxenddo;

a

b

c

(2.2)

Final value

ysqrt20

y:=25

(2.3)

forxtoywhiletruedoprintxenddo;

Error, final value in for loop must be numeric or character

Use the type command to verify whether the value is numeric or character.

typey,'numeric';

false

(2.4)

typey,'character';

false

(2.5)

Ensure that the final value is numeric or character.

forxto25whiletruedoprintxenddo;

1

2

3

4

5

(2.6)

Increment of for loop

forxby2toevalf3whiletruedoprintxenddo;

Error, increment of for loop must be numeric

typesqrt2,'numeric'

false

(2.7)

typeevalfsqrt2,'numeric'

true

(2.8)

Use evalf to evaluate the square root of 2, therefore making the increment numeric.

forxbyevalf2toevalf3whiletruedoprintxenddo;

1

(2.9)

Increment when looping over characters

forifromaby12toewhiletruedoprintienddo;

Error, increment when looping over characters must be an integer

forifromaby2toewhiletruedoprintienddo;

a

c

e

(2.10)

foritogwhiletruedoprintienddo;

Error, final value in for loop must have same type as initial

forito7whiletruedoprintienddo;

1

2

3

4

5

6

7

(2.11)

See Also

evalf

for

numeric