|
|
|
|
|
- Single-line conditional statement
- Condition
- Composite condition
IF statement In french: Si
The conditional IF statement allows you to run an action according to a condition. IF Customer.CalculatedAge > 60 THEN
Elderly += 1
ELSE IF Customer.CalculatedAge > 18 THEN
Adult += 1
ELSE IF Customer.CalculatedAge > 4 THEN
Child += 1
ELSE
Baby += 1
END
IF Customer.City IN ("PARIS", "MARSEILLE", "LYON") THEN
Info("You live in one of the 3 biggest cities in France")
END
IF NOT Customer.City IN ("PARIS", "MARSEILLE", "LYON") THEN
Info("You don't live in one of the 3 biggest cities in France")
END
IF Customer.City NOT IN ("PARIS", "MARSEILLE", "LYON") THEN
Info("You don't live in one of the 3 biggest cities in France")
END
Syntax
Syntax 1
IF <Condition> THEN <Action if condition is True> [ELSE <Action if condition is False>] END
Syntax 2
IF <Condition> THEN <Action if condition is True> [ELSE <Action if condition is False>]
Syntax 3 Hide the details
IF <Condition> THEN <Action if condition is True> [ELSE <Action if condition is False>]
<IF>: Marks the beginning of the statement block. <Condition>: Condition to check. <THEN>: Actions to perform if the condition is True. <Action if condition is True>: Action to perform if the condition is True. <ELSE>: Actions to perform if the condition is False (optional). <Action if condition false>: Action to perform if the condition is False (optional). <END>: Marks the end of the statement block.
Syntax 4 Hide the details
IF <Condition 1> THEN <Action if condition 1 is True> [ELSE IF <Condition 2> THEN <Action if condition 2 is True> [ELSE IF <Condition 3> THEN <Action if condition 3 is True> [...]]] END
<IF>: Marks the beginning of the statement block. <Condition 1>: 1st condition to check. <THEN>: Actions to perform if the previous condition is True. <Action if condition 1 is True>: Action to perform if the 1st condition is True. <ELSE IF>: Checks the next condition if the previous condition is False (optional). <Condition 2>: 2nd condition to check (optional). <Action if condition 2 is True>: Action to perform if the 2nd condition is True and if the 1st condition is False (optional). <Condition 3>: 3rd condition to check. <Action if condition 3 is True>: Action to perform if the 3rd condition is True and if the 1st and 2nd conditions are False. <END>: Marks the end of the statement block. Remarks Single-line conditional statement You also have the ability to use the following syntax: <Result> = <Condition>? <Expression 1> ELSE <Expression 2> Detailed syntax: | | <Result> | Variable to assign with the condition result. | <Condition> | Condition to check. | <Expression 1> | Value assigned to <Result> if the condition is True. | <Expression 2> | Value assigned to <Result> if the condition is False. |
Equivalence: IF <Condition> THEN <Result> = <Expression 1> ELSE <Result> = <Expression 2> END Note: The single-line conditional expression can be used directly in an expression. Example: If age is greater than sixty, count one more person. Otherwise, don't change the number of people. Elderly = Customer.CalculatedAge > 60? Elderly +1 ELSE Elderly
<Condition> can take the following format: | | | Equality test | | Comparison test | | Comparison test | | Comparison test | | Comparison test | - <Value> = <Minimum Expression> TO <Maximum Expression>
| <Value> must be included between the minimum expression and the maximum expression | - <Minimum Expression> <= <Value> <= <Maximum Expression>
| | - <Value> IN (<Expression1>, <Expression2>, ..., <Expression N>)
| <Value> is compared to the result of a list of expressions. All the expressions found in the list are evaluated. The operator returns True if <Value> is equal to at least one of the expressions, False if <Value> is equal to none of the expressions. | - <Value> NOT IN (<Expression1>, <Expression2>, ..., <Expression N>)
| <Value> is compared to the result of a list of expressions. All the expressions found in the list are evaluated. The operator returns False if <Value> is equal to at least one of the expressions, True if <Value> is equal to none of the expressions. | - <Value> _IN_ (<Expression1>, <Expression2>, ..., <Expression N>)
| <Value> is compared to the result of a list of expressions. The expressions are evaluated from left to right. As soon as an expression is equal to <Value>, the remaining expressions are not evaluated and the operator returns True. If <Value> is equal to no expression, the operator returns False. | - <Value> NOT _IN_ (<Expression1>, <Expression2>, ..., <Expression N>)
| <Value> is compared to the result of a list of expressions. The expressions are evaluated from left to right. As soon as an expression is equal to <Value>, the remaining expressions are not evaluated and the operator returns False. If <Value> is equal to no expression, the operator returns True. Caution: There must be a space between "NOT" and "_IN_". |
The AND and OR keywords are used to perform logical operations and to create composite conditions. For example: IF Customer.City = "Montpellier" AND Customer.Title = "Mr" THEN
ManMontpellier ++
END
IF Customer.City = "Montpellier" OR Customer.City = "Lyon" THEN
MontpellierLyon ++
END
The conditions made of AND and OR are entirely evaluated. For example: A > 10 AND B < 20 Even if the first condition (A > 10) is false, the second condition (B < 20) will be checked. Optimizing the evaluation of composite conditions: Use the _AND_ and _OR_ keywords. If the first condition is false (A>10 in our example), the second condition (B<20 in our example) will not be checked. For more details, see Logical operators.
This page is also available for…
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|