Lady Ada

Ada '83 Language Reference Manual

Copyright 1980, 1982, 1983 owned by the United States Government. Direct reproduction and usage requests to the Ada Information Clearinghouse.

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.

Rationale references: 2.2 Textual Structure, 3.9 If Statements

Style Guide references: 2.1.5 More on Alignment, 3.3.7 Marker Comments, 5.6.1 Nesting, 5.6.5 Exit Statements


[Ada Information Clearinghouse]

Address any questions or comments to