controlling variable for loop must be name - 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 : controlling variable for loop must be name

Error, controlling variable of for loop must be a name or sequence of 2 names

Error, controlling variable of for loop must be a name

 

Description

Examples

Description

The for name clause specifies the for loop's control variable. The name may be any expression for which the type(expr, name) command returns a value of true.

 

In Maple 2019 and later, you can also provide a sequence of two names as the loop's control variables.  In that case, during each iteration of the loop, those two variables are used as the index and value of the entry.

 

This error message occurs when the control variable used in the for loop is not of type name (or a sequence of two names), that is, expressions for which the type(expr, name) command returns a value of false.

Examples

Example 1

In this case, the control variable has been omitted.

for  from 6 by 2 to 10 doprintiend do

Error, controlling variable of for loop must be a name or sequence of 2 names


Solution:

The name i has been designated as the control variable.

for i from 6 by 2 to 10 doprintiend do

6

8

10

(2.1)

Example 2

This error occurs because the specified controlling variable is not a name.

total0:

for sinx from 1 to 10 do totaltotal+2 end do:

Error, controlling variable of for loop must be a name or sequence of 2 names

type'sinx', 'name'

false

(2.2)


Solution 1:

Replace sinx with an expression for which type(expr, name) returns true. For example, replacing sinx with x corrects the error.

total0: 

for x from 1 to 10 do totaltotal+2 end do:

total

20

(2.3)


Solution 2:

In this particular example, you can omit the for clause.  In this solution, we use a simple counted loop.

total0: 

from 1 to 10 do totaltotal+2 end do:

total

20

(2.4)

For more information and basic examples of the different types of loops, see Repetition Statements in the Maple Programming Guide.

See Also

for loops

repetition statements in the Programming Guide

type/name