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 = 18F25K20 ' Use an 18F device
Declare Xtal = 16 ' Tell the compiler the device is operating at 16MHz
Declare Hserial_Baud = 9600 ' Choose the Baud rate for HRsoutLn
Dim MyWord as Word ' Create an unsigned Word variable
MyWord = 1
Repeat
HRsoutLn Dec MyWord
DelayMs 200
Inc MyWord
Until MyWord > 10
or
Repeat High LED : 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
See also : Bound, Do...Loop, For...Next...Step, SizeOf, While...Wend.
