Modifying the bounds/step of a FOR loop inside the loop is forbidden

Navigation:  Messages > Macro Compiler Messages > Errors >

Modifying the bounds/step of a FOR loop inside the 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 any of the variables that are used to calculate the expressions for the start point, end point and step value of the loop.

 

Example

 

for nCtr = nStart to nEnd step nInc

 nStart = nCtr + 2 // NO !!!

 nEnd   = nCtr + nStart // NO !!!

 nInc   = nTokenDayValue div 2 // NO !!!

endfor

 

The reasons behind this restriction are :

 

Shifting the parameters of a for instruction makes it hard to follow for human readers, including the person writing the Macro, and can easily lead to bugs.

 

The compiled code is optimized to take advantage of the fact that all the elements of a for loop remain constant, during the loop. Changing this would make for slower execution of loops at run-time.

 

Allowing the end point or step value to change could lead to an infinite loop (as would happen in the above example).

 

Note that using the counter variable (which changes automatically at the end of each loop iteration) in any of the expressions used to calculate the start point, end point and step value of the loop, is also forbidden.

 

If you feel you must absolutely change the value of any the for loop variables, 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 the counter variable within a FOR loop is forbidden.


Topic 108998 updated on 11-Apr-2002.
Topic URL: http://www.qppstudio.net/webhelp/index.html?modifyingcountervariableinside.htm