Purpose | The for statement is used to loop repeatedly until a certain limit is reached. At each iteration of the loop some Superx++ statements can be executed. | |||||||||
Format |
for({initial statements}; {loop condition}; {step statements}) { {iteration statements} }; {initial statements} |
the statements to be executed before the first iteration of the loop. |
{loop condition} |
the condition to be evaluated: if true then the loop will continue; if false then the loop will terminate. |
{step statements} |
the statements to be executed after each iteration of the loop. |
{iteration statements} |
the statements to be executed with each iteration of the loop before the {step statements}. |
|
|
Example #1 |
class XEmployee { public: int MyCount; }; node(XEmployee) MyEmp; for (MyEmp.MyCount = 0; MyEmp.MyCount < 10; MyEmp.MyCount = MyEmp.MyCount + 1) { xout("\r\nFor\tinstance = " + MyEmp.MyCount); };
The loop starts by executing setting MyEmp.MyCount to 0. Then the loop condition executes to evaluate whether or not the loop should continue or terminate and pass control to the next statement in the program. If the loop condition evaluated to true then the statements found after the step statement are executed. After they have executed, the step statement executes and then the loop condition is re-executed and the cycle continues. The result of the code above is that the following text is sent to the output stream: |