Skip to content

Repeat

See Also: Boolean Expressions, Execution Control Commands, For, Loop, Until, While, Break, Boolean

Purpose

Executes a repeating block of code.

Syntax

Repeat
Until {Boolean-expression}

What It Does

The Until command sends execution back to the last previous Repeat command until the {Boolean-expression} becomes true. When the {Boolean-expression} becomes true, execution proceeds to the command following the Until command.

A Repeat ... Until block will still execute once even if the {Boolean-expression} is true, unless you program the Repeat command with conditionals to also make it subject to the {Boolean-expression}.

Example

This sample shows how to loop through table rows using the global record buffer. It assumes that Index 1 of the Customer table is Customer_Number and unique (the only segment in this index).

Clear Customer
Repeat
    Find GT Customer By 1  // Index 1 = Customer_Number
    If (Found) Begin
        // do something with the customer record
    End
Until
    (not(Found))
Send ShowDetails

The function method InventoryCheck executes repeatedly until the Boolean variable bFinished is true. Execution then continues on to the next command.

Boolean bFinished
Repeat
    Get InventoryCheck To bFinished
Until bFinished

In this example, 1 is added to the variable iPlayers repeatedly until it is greater than or equal to 10. Keep in mind that iPlayers starts at 0, since it is not specifically initialized to a value.

Integer iPlayers
Repeat
    increment iPlayers
Until (iPlayers >= 10)

Notes

  • Repeat loops may also be terminated with loop (although this technique is unusual).

  • You may place Repeat ... Until blocks inside other looping blocks, up to a limit of 40. You may freely intermingle the various types of loops, but you may not overlap them—you must end the innermost block first, then the next innermost, and so on.

  • You may exit from the middle of a loop by using break. If your loop is within a function or procedure (which it typically is), it may be terminated with function_return or procedure_return, which also terminate the function or procedure.

  • Statements inside blocks are usually indented to make the blocks more readable.

  • Repeat is an unconditional initiator. For a conditional initiator, use while.