With a Repeat loop, you can execute one or more statements as long as a certain condition is not met.

The Repeat loop is the opposite of the While loop. In the While loop, you stay in the loop as long as the starting condition is True. When it becomes False, you break the loop. In the Repeat loop, it is the other way round: You stay in the loop as long as the exit condition is False. When it becomes True, the loop is ended. This means that you can rewrite each While loop as a Repeat loop and vice versa, as long as you logically reverse the condition that you use to start (or stop) it.

The only other difference between these two loops is that a Repeat loop is executed at least once, even if the condition you use to stop it is True from the start. With a While loop, you can set the starting conditions so that the loop is not executed at all under certain circumstances.

Same as with While loops, you have to take care to provide a statement that can eventually break the Repeat loop, that means the breaking condition must become True at some point.


Until Condition;


Starts the Repeat loop execution block that is executed at least once


Any command statements that will be executed once, and then as long as the loop condition is met.


Starts the Until control block that determines when the loop will end


Boolean expression that controls the loop: As long as it is False, the loop will continue. When it becomes True, the loop is broken.

Most Repeat loops use more than one command statement, as you have to add statements to break the loop: You must provide a possibility for the condition to become True. Otherwise, your loop will never be broken and run indefinitely. Note that for Repeat loops, you do not have to use Begin ... End if there is more than one command statement inside the loop.


This is the same example as in the section on While loops. Note that the condition i < period has been reversed:

i = 0;
   Result = Result + source[i];
   i = i + 1;
Until i >= period;