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 prevent the loop from terminating.

 

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 17-Oct-2026