Please enable JavaScript to view this site.

 

Navigation: Macros > Macro Language > Compiler Messages > Errors

Modifying the counter variable within a FOR loop is forbidden

Scroll Prev Up Next More

This compiler error will occur if, within a for loop, you try to modify the value of its counter variable.

 

For example:

for nCtr = nStart to nEnd step nInc
   nCtr = nCtr div 2 // NO !!!
endfor

The reason behind this restriction is that allowing the counter variable to change could lead to an infinite loop (as would happen in the above example).

 

If you feel you must absolutely change the value of the counter variable, this is a sign that you should be using a while loop instead of a for loop. For a discussion on which of the loops to use, see looping instructions.

 

See also: modifying a for loop variable inside its loop is forbidden.

 


Topic 108217, last updated on 18-Apr-2020