Modifying the counter variable within a FOR loop is forbidden

Navigation:  Messages > Macro Compiler Messages > Errors >

Modifying the counter variable within a FOR loop is forbidden

Previous pageReturn to chapter overviewNext page

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

 

Examples

 

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 updated on 11-Apr-2002.
Topic URL: http://www.qppstudio.net/webhelp/index.html?modifyingthecountervariablewit.htm