PC SOFT

WINDEVWEBDEV AND WINDEV MOBILE
ONLINE HELP

Home | Sign in | English UK
  • Single-line conditional statement
  • Condition
  • Composite condition
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadApple WatchUniversal Windows 10 AppWindows Mobile
Others
Stored procedures
The conditional IF statement allows you to run an action according to a condition.
Example
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
// Use of 'IN'
IF Customer.City IN ("PARIS", "MARSEILLE", "LYON") THEN
Info("You live in one of the 3 biggest cities in France")
END

// Use of 'NOT x IN'
IF NOT Customer.City IN ("PARIS", "MARSEILLE", "LYON") THEN
Info("You don't live in one of the 3 biggest cities in France")
END

// Use of 'NOT IN' (from version 23)
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 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 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 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 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
Remark: The single-line conditional expression can be directly used in an expression.
Example: Increment the number of persons when the age is greater than 60, otherwise the number of persons remains the same.
Elderly = Customer.CalculatedAge > 60? Elderly +1 ELSE Elderly

Condition

<Condition> can take the following format:
  • <Value> = <Expression>
Equality test
  • <Value> < <Expression>
Comparison test
  • <Value> <= <Expression>
Comparison test
  • <Value> > <Expression>
Comparison test
  • <Value> >= <Expression>
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.
  • Versions 23 and later
    <Value> NOT IN (<Expression1>, <Expression2>, ..., <Expression N>)
    New in version 23
    <Value> NOT IN (<Expression1>, <Expression2>, ..., <Expression N>)
    <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.
  • Versions 23 and later
    <Value> NOT _IN_ (<Expression1>, <Expression2>, ..., <Expression N>)
    New in version 23
    <Value> NOT _IN_ (<Expression1>, <Expression2>, ..., <Expression N>)
    <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.

Composite condition

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 ++   // Number of men living in Montpellier
END

IF Customer.City = "Montpellier" OR Customer.City = "Lyon" THEN
        MontpellierLyon ++ // Number of customers living in Montpellier or in Lyon
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. See Logical operators for more details.
Minimum version required
  • Version 9
This page is also available for…
Comments
Click [Add] to post a comment