Skip to content
Developer Edition runs on one host and does not require a product license file. Need multi-host deployment or performance testing at scale? Explore Enterprise Edition

Control flow statements

The control flow statements control the execution order of statements in a procedure.

The following control flow statements are supported:

  • WHILE: executes a series of statements in a loop for as long as a specified condition is true.
  • IF: executes a series of statements based on a specified condition.
  • BREAK: exits a loop immediately. It is typically used within a WHILE statement or within an IF statement that is inside a loop.
  • CONTINUE: skips the remaining statements in the current iteration and proceeds to the next iteration. It is typically used within a WHILE statement or within an IF statement that is inside a loop.

Syntax

while_statement
WHILE value_expression THEN { procedure_body }
if_statement
IF value_expression THEN { procedure_body } ELSEIF value_expression THEN { procedure_body } ELSE { procedure_body }
break_statement
BREAK
continue_statement
CONTINUE

while_statement ::=
  'WHILE' value_expression 'THEN' '{' procedure_body '}'

if_statement ::=
  'IF' value_expression 'THEN' '{'  procedure_body '}' 
  ( 'ELSEIF' value_expression 'THEN' '{'  procedure_body  '}' )*
  ( 'ELSE' '{'  procedure_body  '}' )?   

break_statement ::=
  'BREAK'    

continue_statement ::=
  'CONTINUE'     

Parameters

value_expression

A value expression that evaluates to a boolean value. For more information, see Boolean type and Expressions.

procedure_body

A set of statements to be executed. For more information, see Procedure body.

Examples

WHILE

'''
VALUE i INT = 0 
WHILE i < 5 THEN { 
  SET i = i + 1 
} 
RETURN i
'''

Return:

+---+
| i |
+---+
| 5 |
+---+

IF

IF-ELSE

'''
VALUE i INT = 5 
IF i < 5 THEN { 
  SET i = i + 1 
} ELSE { 
  SET i = i - 1 
} 
RETURN i
'''

Return:

+---+
| i |
+---+
| 4 |
+---+

IF-ELSEIF-ELSE

'''
VALUE i INT = 4 
IF i < 3 THEN { 
  SET i = i + 1 
} ELSEIF i < 5 THEN { 
  SET i = i + 2 
} ELSE { 
  SET i = i - 1 
} 
RETURN i
'''

Return:

+---+
| i |
+---+
| 6 |
+---+

BREAK

'''
VALUE i INT = 0 
WHILE i < 5 THEN { 
  IF i = 3 THEN { 
    BREAK 
    } 
  SET i = i + 1 
} 
RETURN i 
'''

Return:

+---+
| i |
+---+
| 3 |
+---+

CONTINUE

'''
VALUE i INT = 0 
WHILE i < 5 THEN { 
  IF i < 3 THEN { 
    SET i = i + 1 
    CONTINUE 
  } ELSE { 
    SET i = i + 1 
  } 
} 
RETURN i
'''

Return:

+---+
| i |
+---+
| 5 |
+---+