Control Statements

If/Else Statement

If statements are used to define conditional options.

Syntax:

If statements follow syntax similar to C and C++:

If (condition)

{

   Expression in case of true condition

}

Else

{   

Expression in case of false condition

}

The condition is an expression that is regarded as a Boolean value to be tested by the If statement. This can be a logical expression, a comparison, or a Boolean constant; any other expression will be converted to Boolean and be tested (see the AsBoolean Function in the Conversion Functions topic).

The Else part is optional. If the predicate is evaluated to False and there is no Else statement, the value of the If statement is Null.

Example:

if(@{age} > 60)

"senior"

else if(@{age} > 20)

"adult"

else

"young"

Switch Statements

A Switch statement is a simplified way to write a multi-choice 'If' statement.

Syntax:

The Switch statement uses the following syntax:

Switch (expression)

{

 Case literal1:

   Expression1

 Case literal2:

   Expression2

 Default:

   DefExpression

}

The Default case is optional. If no case matches the expression and there is no default case, the value of the Switch statement is Null.

Example:

Switch (@{category})

{

   Case "PLATINUM":

      250000

   Case "GOLD":

      70000

   Case "SILVER":

      30000

   Default:

      10000

}