@Babloo: I hoped the pattern would become clear in the examples.
@Astounding: Thanks for the explanation. I had already started to write something similar, but had to leave my office.
Here it is:
Let's consider an iterative DO loop of the form "do i=a to b by c;" with reasonable numbers a, b and c, c ne 0. Please note that c=1 by default if it is not specified, i.e. in the case "do i=a to b;". Let's further assume that the loop is not left prematurely due to a statement such as LEAVE, GOTO or LINK and that the value of variable i is not changed by assignment statements and the like.
My understanding is:
Step 1: At the beginning of the loop, i is set to a.
Step 2: It is checked whether an iteration of the loop will occur. No iteration will occur (i.e., the code inside the DO loop will not be executed) if either c>0 & a>b or c<0 & a<b. In this case, we still have i=a after the loop. (The corresponding example was "do i=2 to 0;".) Otherwise, continue with Step 3.
Step 3: The code inside the DO loop is executed with the current value of i.
Step 4: Variable i is incremented like i=i+c.
Step 5: It is checked whether another iteration of the loop will occur. No further iteration will occur and the loop will finish if either c>0 & i>b or c<0 & i<b. In this case, the current value of i is the one which will be present immediately after finishing the loop. Otherwise, continue again with Steps 3, 4, 5.
... View more