Positron Compiler Documentation

Repeat...Until

Positron8 · Revision 4.0.6.5 · PDF page 313

Repeat Condition Instructions Instructions Until Condition

or

Repeat { Instructions : } Until Condition

Execute a block of instructions until a condition is true.

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

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.

View original PDF page 313Open page in PDFOriginal PDF page 313