Error, controlling variable of for loop must be a name - Maple Programming Help

Home : Support : Online Help : System : Error Message Guide : controllingvariableforloopmustbename

Error, controlling variable of for loop must be a name

 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.   This error message occurs when the control variable used in the for loop is not of type name, 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.

 >
 $\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}6\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{by}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}2\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{to}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}10\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{do}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathrm{print}\left(i\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{end do}$

Solution:

The name has been designated as the control variable.

 >
 ${6}$
 ${8}$
 ${10}$ (2.1)

Example 2

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

 > $\mathrm{total}≔0:$
 >
 $\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{from}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}1\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{to}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}10\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{do}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathrm{total}≔\mathrm{total}+2\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{end}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{do}:$
 >
 ${\mathrm{false}}$ (2.2)

Solution:

Replace $\mathrm{sin}\left(x\right)$ with an expression for which type(expr, name) returns true. For example, replacing with corrects the error.

 >
 > $\mathrm{total}$
 ${20}$ (2.3)