Language Reference
Documentation

Language

Objects
Internet Objects

Flow Statements

IF | DO-LOOP | FOR-NEXT | SELECT

IF STATEMENT

Conditionally executes a group of statements, depending on the value of a boolean expression.


IF expression THEN
Statement...
[ELSEIF expression THEN
Statement...]
[ELSE
Statement...]
END IF


FOR NEXT STATEMENT

Executes a series of statements a specified number of times.

FOR counter = start TO end [STEP step]
Statement...
NEXT

FOR counter = start DOWNTO end
Statement...
NEXT


Counter is an integer variable that will be incremented. Start can be any numeric expression or variable that returns an integer, this is the initial value. End is an integer variable or constant, this is the final value. Step is an integer variable or constant. When step is included counter will be incremented.

The statements will be executed each time until counter is greater than end or if DownTo is used until counter is less than end .

Another variation of the FOR...NEXT loop is the FOR...IN loop. The FOR...IN loop allows you to easily loop through the elements of an array or list. For more info see arrays.

DO...LOOP STATEMENT

Repeatedly executes a group of statements while the value of an expression is true.

DO UNTIL expression
Statement…
LOOP

DO WHILE expression
Statement…
LOOP


SELECT CASE STATEMENT

Conditionally executes one group of statements from several groups, depending on the value of an expression.

SELECT CASE expression
CASE value1[,value2]…
Statement Group1…
[CASE value3
Statement Group2…]
.
.
.
[DEFAULT
Statement Group…]
END SELECT


The expression must evaluate to a numeric or string value. The statement group inside the DEFAULT is executed if none of the previous CASE values match the expression.

Sample Code

declare function getSomeValue()
Sub Main()
    dim i as string
    i = "jose"
    select case i
    case "joe",getSomeValue
        msgbox("Error: i=jose")
    default
        msgbox("OK: Sorry, try again")
    end select
    msgbox("The END")
end sub
Function getSomeValue()
    return "jose3"
End Function

//sample 2

msgbox("Testing DownTo")

for i = i Downto 1
    msgbox(i)
next

msgbox("i is now " & i)
msgbox("Testing Step")

for i = i To 10 Step 2
    msgbox(i)
next

msgbox("i is now " & i)
msgbox("Testing Negative step")

for i = 10 To 0 Step -2
    msgbox(i)
next

msgbox("i is now " & i)
msgbox("Test completed...")

//if sample

dim i as integer
dim r as string
i = 5
r = "jose"
msgbox("Testing IF")
if i = 2 then
    msgbox("Error i is not two")
elseif i = 7 then
    msgbox("Error i is not seven")
elseif i = 5 then
    msgbox("OK i is five")
    if r = "joe" then
        msgbox("Error r is not joe")
    elseif r = "jose" then
        msgbox("OK r is jose")
    else
        msgbox("Error r not matched")
    end if
elseif i = 9 then
    msgbox("Error i is not seven")
else
    msgbox("Error ElseIf not matched")
end if