loopwhile
loopwhile
FORMULA

The loopwhile statement is used at the beginning of a loop.

Parameters

This statement has one parameter:

formula – is a formula that should result in a true (–1) or false (0) answer. Usually the formula is created with a combination of comparison operators (=, <>, etc.) and Boolean combinations (and, or, etc.) For example the formula `Last="Smith"` will be true if the field or variables Last contains the value Smith, and false if it contains any other value.

Description

The loopwhile statement is used at the beginning of a loop that iterates as long as a formula is true. As soon as the formula is false, the loop stops. In fact, if the formula is false before the loop begins, the statements in the loop are never executed. The end of a loopwhile loop is always an endloop statement.

This example takes a string of text and makes it shorter each time through the loop. When the text is all gone, the loop stops.

    local text
    text="abcd"
    loopwhile text<>""
       message text
       text=text[1,-2]
    endloop

With the text set to abcd, this loop will run 4 times, with the following results:

    ☞ abcd
    ☞ abc
    ☞ ab
    ☞ a

If the text variable was empty (`""`), the statements in the loop would be skipped entirely, and no message would appear at all.

Error Messages

LOOP without ENDLOOP – Each LOOP statement must be paired with a corresponding ENDLOOP, UNTIL or WHILE statement. If this error message appears, the necessary statement terminating the loop has not been included.

See Also

- endloop -- is used at the end of a loop.
- for -- is used at the beginning of a loop that loops a fixed number of times.
- info("timelimitremaining") -- returns the amount of time available (in seconds) before a loop will time out.
- loop -- is used at the beginning of a loop.
- looparray -- is used at the beginning of a loop that loops over the elements of an array.
- loopdataarray -- is used at the beginning of a loop that loops over the elements of a data array.
- loopindex -- allows a procedure to determine how many times a loop has been repeated.
- Preventing Endless Loops -- setting up a timeout limit to prevent endless loops.
- repeatloopif -- decides whether to continue with a loop or to start over again from the top.
- stoploopif -- decides whether to continue with a loop or to exit the loop immediately.
- timelimit -- specifies the maximum time a procedure can continue to run after this statement.
- until -- is used at the end of a loop, and can control how many times the loop is executed.
- while -- is used at the end of a loop, and can control how many times the loop is executed.

History

Version | Status | Notes
10.0 | New | New in this version