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
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.
Example 1
In this case, the control variable has been omitted.
for from 6 by 2 to 10 doprintiend do
Solution:
The name i has been designated as the control variable.
for i from 6 by 2 to 10 doprintiend do
6
8
10
Example 2
This error occurs because the specified controlling variable is not a name.
total≔0:
for sinx from 1 to 10 do total≔total+2 end do:
type'sinx', 'name'
false
Solution 1:
Replace sinx with an expression for which type(expr, name) returns true. For example, replacing sinx with x corrects the error.
for x from 1 to 10 do total≔total+2 end do:
total
20
Solution 2:
In this particular example, you can omit the for clause. In this solution, we use a simple counted loop.
from 1 to 10 do total≔total+2 end do:
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
Download Help Document