repeatloopif
repeatloopif
FORMULA

The repeatloopif statement decides whether to continue with a loop or to start over again from the top.

Parameters

This statement has one parameter:

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

Description

This statement decides whether to continue with a loop or to start over again from the top. If the test is true, the loop will start over again from the top. If the test is false, the loop will continue normally.

This example builds a list of the alphabetic letters used in the field Notes. The repeatloopif statement uses the rangenotmatch( function to check whether or not a character is alphabetic. If it is not alphabetic, the loop starts over again from the top, skipping the rest of the loop for that character.

    local oneLetter,usedLetters
    usedLetters=""
    for n,1,length(Notes)
        oneLetter=upper(Notes[n;1])
        repeatloopif  rangenotmatch(oneLetter,"AZ")
        if usedLetters notcontains oneLetter
            usedLetters=usedLetters+oneLetter
        endif
    endloop

This slightly more complex example generates a lotto Power Ball random pick consisting of 5 unique numbers between 1 and 59 and one Power Ball number between 1 and 35. The repeatloopif statement uses the arraycontains( function to check to see if the last generated random number already exists in the array. If it already exists, the loop starts over again from the top, skipping the rest of the loop for that generated number.

    local wnumbers, pbnumber, cachenumbers
    cachenumbers=padzero(str(randominteger(1,59)),2)
    pbnumber=padzero(str(randominteger(1,35)),2)
    loopwhile arraysize(cachenumbers,“ ”)<5
        wnumbers=padzero(str(randominteger(1,59)),2)
        repeatloopif arraycontains(cachenumbers,wnumbers,“ ”)
        cachenumbers=cachenumbers+“ ”+wnumbers
        wnumbers=arraynumericsort(cachenumbers,“ ”)
    endloop
    message wnumbers+“: ”+pbnumber

Error Messages

REPEATLOOPIF must be used between LOOP and ENDLOOP statements – The repeatloopif statement cannot be used outside of a loop.

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.
- loopwhile -- is used at the beginning of a loop.
- Preventing Endless Loops -- setting up a timeout limit to prevent endless loops.
- 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 | No Change | Carried over from Panorama 6.0.