5.3. If Statements


An if statement selects for execution one or none of the enclosed sequences of statements, depending on the (truth) value of one or more corresponding conditions.

    if_statement ::=
        if condition then
       {elsif condition then
        end if;    

    condition ::= boolean_expression  

An expression specifying a condition must be of a boolean type.

For the execution of an if statement, the condition specified after if, and any conditions specified after elsif, are evaluated in succession (treating a final else as elsif TRUE then), until one evaluates to TRUE or all conditions are evaluated and yield FALSE. If one condition evaluates to TRUE, then the corresponding sequence of statements is executed; otherwise none of the sequences of statements is executed.


    if MONTH = DECEMBER and DAY = 31 then
       MONTH := JANUARY;
       DAY   := 1;
       YEAR  := YEAR + 1;
    end if; 

    if LINE_TOO_SHORT then
       raise LAYOUT_ERROR;
    elsif LINE_FULL then
    end if; 

    if MY_CAR.OWNER.VEHICLE /= MY_CAR then            --  see 3.8
       REPORT ("Incorrect data");
    end if; 

References: boolean type, evaluation, expression, sequence of statements.