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


History

VersionStatusNotes
10.0No ChangeCarried over from Panorama 6.0.