Databases Reference
In-Depth Information
Other control statements of interest are:
Control statement
Explanation
Example
DO
LOOP
Execute statements WHILE or
UNTIL a condition is met.
DO WHILE i< 10
[executed while i is less than 10 ]
LOOP
FOR
NEXT
Use a counter to loop over
statements.
FOR i = 1 TO 10
[executed for values 1 to 10 ]
NEXT
FOR EACH
NEXT
Loop over statements for each
value in a comma separated
list.
FOR EACH i IN A, B, C
[executed for A , B and C ]
NEXT
IF
THEN
ELSEIF
ELSE
END IF
IF i = 1 THEN
[executed when i = 1 ]
ELSEIF i = 2 THEN
[executed when i = 2 ]
ELSE
[executed when i not 1 or 2 ]
END IF
Follow a different path based
on which condition is met,
this is the control statement
we used in our example. The
ELSEIF and ELSE conditions
are optional.
SWITCH
CASE
DEFAULT
END SWITCH
Execute a different group of
statements ( CASE ) based on
the value of an expression.
If no match is found for
the value, the DEFAULT
statements are executed.
SWITCH i
CASE 1
[executed when i is 1 ]
CASE 2
[executed when i is 2 ]
DEFAULT
[executed when i not 1 or 2]
END SWITCH
A special type of control statement is the SUB .. END SUB statement. This defines a
subroutine, a piece of script that can be called from other parts of the script. We will
look into this in more detail later in the Re-using scripts section of this chapter.
Search WWH ::




Custom Search