WHILE Loops

Navigation:  Appendices > Macro Language > Compiled Code > Compiled Code Samples >

WHILE Loops

Previous pageReturn to chapter overviewNext page

As you may have noticed there is no op-code for the while statement. The reason is that there is no need for it. The while loop is an if branch with the following differences :

 

At the end of the "true" branch, the branching condition is tested again. If the condition is true again, the "true" code block is performed again and again until the branching condition is false.

There is no else part. If the branching condition is false, the whole while block is skipped.

 

Consider the following source code.

 

while bCondition

 // do something

endwhile

 

When compiled it generates the following (the letters in the margin are added here for illustration purposes).

 

a) 0008 IF_001 @bCondition jne+0002

 

b) 0010 JMP-0001  //GOIF_001

c) 0010 ENDF_001

 

We see that the code sequence is as follows

 

ab                // every loop

ab                // …

ac                // until bCondition is false and jne+0002 jumps to c

 

While the while keyword is different in source code, at the level of the compiled code, it is not very different from if.


Topic 108221 updated on 29-Jun-2005.
Topic URL: http://www.qppstudio.net/webhelp/index.html?whileloops.htm