Skip to content

While do end

Description

This statement can be used to execute a loop.

Syntax

While <Expression> Do 
    <Statements> 
End

Sample

Dim sTestVal
Dim iLength
Dim sTestChar
Dim bStop
Dim iCnt

Let sTestVal = '1234X5678'
Let iLength = len(sTestVal)
Let sTestChar = ''
Let bStop = 0
Let iCnt = 1

// test if the variable 'testval' only consists of numbers
While ((iCnt <= iLength) And (bStop = 0)) Do
    Let sTestChar = Mid(sTestVal,iCnt,1)
    Let bStop = (Not(Instr('1234567890',sTestchar)))
    Let iCnt = (iCnt + 1)
End

If (bStop = 0) then
    Return 'variable consists only of numbers'
Else
    Return 'variable does not only consist of numbers'
End

The above example tests if a variable consists only of numbers. The characters are tested one by one. If a character is found that is not a number, the loop is exited.

Notes

  • The while loop automatically terminates when it iterates for more than 1000 times to avoid infinite recursion (the program becomes unresponsive).