REPEAT - UNTIL
You can use the REPEAT - UNTIL statement to create a loop that continues to execute until a specified condition occurs. Use the following format:
- REPEAT
- <Statements>;
- UNTIL
- <Condition>
- END_REPEAT
where <Statements> defines the values and methods that are set by the program in the REPEAT statement. <Condition> is the value that causes the program to stop repeating the Logic defined in the REPEAT statement.
Example:
You can use a REPEAT - UNTIL program to increase a count by 1 and a value by 10 until the value reaches 100:
- REPEAT
- CountValue := CountValue+1;
- CurrentValueFormatted : = CurrentValueFormatted +10;
- CountValue := CountValue+1;
- UNTIL
- CurrentValueFormatted >=100
- CurrentValueFormatted >=100
- END_REPEAT;
where CountValue and CurrentValueFormatted are the names of variables (which needs to be defined in the VAR list).
In this example, the program increases the CountValue by 1 and the CurrentValueFormatted by 10 on each execution. This part of the program repeats itself until the CurrentValueFormatted is equal to or greater than 100.
REPEAT statements are performed at least once (because the condition is at the end of the statement). In the example, if the CurrentValueFormatted is 200 when the program starts, the program will still increase the CountValue by 1 and the CurrentValueFormatted by 10 once.