Repeat...Until
Syntax
Repeat Condition Instructions Instructions Until Condition
or
Repeat { Instructions : } Until Condition
Overview
Execute a block of instructions until a condition is true.
Example
Device = 24HJ128GP502
' Select the device to compile for
Declare Xtal = 16
Dim MyWord as Word
MyWord = 1
Repeat
Print Dec MyWord, " "
DelayMs 200
Inc MyWord
Until MyWord > 10
or
Repeat PinHigh LED_Pin : Until PORTA.0 = 1 ' Wait for a Port change
Notes.
The Repeat-Until loop differs from the While-Wend type in that, the Repeat loop will carry out the instructions within the loop at least once, then continuously until the condition is true, but the While loop only carries out the instructions if the condition is true.
The Repeat-Until loop is an ideal replacement to a For-Next loop, and actually takes less code space, thus performing the loop faster.
Two commands have been added especially for a Repeat loop, these are Inc and Dec.
Inc. Increment a variable i.e. MyWord = MyWord + 1
Dec. Decrement a variable i.e. MyWord = MyWord - 1
The above example shows the equivalent to the For-Next loop: -
For MyWord = 1 to 10 : Next