Error, final value in for loop must be numeric or character - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Mozilla Firefox.

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : Error, final value in for loop must be numeric or character

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

 

Description

Examples

Description

The terminal condition in a for loop must be a numeric value, except when iterating over the letters in a string where a character is accepted.

Examples

Example 1

Note that n has no value.

 

> 

for i from 1 to n do     sinπ2⋅iend do;

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

 

Solution:

Define n  to correct this error.

> 

n≔4

n:=4

(2.1)
> 

for i from 1 to n do     sinπ2⋅iend do;

1

0

−1

0

(2.2)

 

Example 2

In this example x is set to 13−j where j has no value.

> 

G≔procx      local i≔1;      to x do           i≔i⋅x      end do  end proc:

> 

G13−j

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

 

Solution:

As with the previous example, define  j to correct this error.

> 

j≔7

j:=7

(2.3)
> 

G13−j

46656

(2.4)

 

Example 3

Here N is not initialized to a numeric value.

 

> 

for n to N−1 do      xn+1 ≔ xn+Δxn; yn+1 ≔ yn+Δyn  end do;

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

 

Solution:

Initialize N.

> 

N≔5

N:=5

(2.5)
> 

for n to N−1 do      xn+1 ≔ xn+Δxn; yn+1 ≔ yn+Δyn  end do;

x2:=x1+Δx⁡1

y2:=y1+Δy⁡1

x3:=x1+Δx⁡1+Δx⁡2

y3:=y1+Δy⁡1+Δy⁡2

x4:=x1+Δx⁡1+Δx⁡2+Δx⁡3

y4:=y1+Δy⁡1+Δy⁡2+Δy⁡3

x5:=x1+Δx⁡1+Δx⁡2+Δx⁡3+Δx⁡4

y5:=y1+Δy⁡1+Δy⁡2+Δy⁡3+Δy⁡4

(2.6)

See Also

loops