The If Statement

Syntax

$ IfStatement = IF expression THEN StatementSequence

{ELSEIf expression THEN StatementSequence}

[ELSE StatementSequence]

END IF ";"

Description

The If statement ensures conditional execution of statements depending on the specified logical expressions. The block of statements starts with the If...Then keywords, between them the checked expression is specified. Then there several optional blocks Elseif...Then may follow, containing other checked expressions. If there is an expression, which value is True, the statements sequence is executed. The Else block can be specified after all the blocks, the block contains the statements that will be executed, if none of the expressions returns True. After a statements sequence is executed, the statement following the If statement takes control.

Example

Sub IfSample;
Var
    a, b: Integer;
    c: Double;
Begin
    //...
    //Get values a, b, c
    //...
    If (a > b) And (b > c) Then
        c := a - b;
    Elseif (a < b) And (b < c) Then
        c := b - a;
    Else
        c := (a + b) / 2
    End If;
    //...
End Sub IfSample;

See also:

Statements