Go to the first, previous, next, last section, table of contents.

5.3 If Statements

  1. An if_statement selects for execution at most one of the enclosed sequences_of_statements, depending on the (truth) value of one or more corresponding conditions.


  2. if_statement ::=
        if condition then
        {elsif condition then
        end if;
  3. condition ::= boolean_expression

    Name Resolution Rules

  4. A condition is expected to be of any boolean type.

    Dynamic Semantics

  5. 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 a condition evaluates to True, then the corresponding sequence_of_statements is executed; otherwise none of them is executed.


  6. Examples of if statements:
  7. if Month = December and Day = 31 then
       Month := January;
       Day   := 1;
       Year  := Year + 1;
    end if;
  8. if Line_Too_Short then
       raise Layout_Error;
    elsif Line_Full then
    end if;
  9. if My_Car.Owner.Vehicle /= My_Car then  --  See section 3.10.1 Incomplete Type Declarations
       Report ("Incorrect data");
    end if;

Go to the first, previous, next, last section, table of contents.