[Home] [Prev] [Next] [Index]

5.3 If Statements

5.3 If Statements

1
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.

2
if_statement ::=
      if condition then
      sequence_of_statements
      {elsif condition then
      sequence_of_statements}
      [else
      sequence_of_statements]
      end if;

condition ::= boolean_expression

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

4
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.

5
Examples:

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
      NEW_LINE; PUT(ITEM);
else
      PUT(ITEM);
end if;

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

6
References:

*
boolean type 3.5.3

*
evaluation 4.5

*
expression 4.4

*
sequence of statements 5.1



[Home] [Prev] [Next] [Index]

documentation@rational.com
Copyright © 1993-2000, Rational Software Corporation. All rights reserved.