Iteration Structures
Previous  Top  Next


These structures allow to repeat a lot of operations until certain condition.

1."for" VAR ":=" EXPR "to" EXPR "do" BLOCK |  
2."for" VAR ":=" EXPR "downto" EXPR "do" BLOCK |  
3."while" EXPR "do" BLOCK |  
4."repeat" BLOCKLIST "until" EXPR |  

INSTR =    "for" VAR ":=" EXPR "to" EXPR "do" BLOCK |
INSTR =    "for" VAR ":=" EXPR "downto" EXPR "do" BLOCK |

The cycle For executes actions for a lot of predefined times, increasing (to) or decreasing (downto) of a unit a variable counter for each cycle.

INSTR =    "while" EXPR "do" BLOCK |


The While cycle executes some actions until the condition is true, when the condition becomes false it leaves the cycle. In this cycle the condition is checked before the execution.

-Example :  
//it writes the same string until the end of the file (not TextFileEOF=True)
While not TextFileEOF do
Begin  
//it writes a string into the file  
text:=TextFileWriteln(UnFile,'Luca Rossi');  
End;  

INSTR =    "repeat" BLOCKLIST "until" EXPR |

The Repeat cycle executes some actions as long as the condition is false, when the condition becomes true it leaves the cycle. In this cycle the condition is checked after the execution.