[Ada Information Clearinghouse]
Ada '83 Rationale, Sec 3.9: If Statements

"Rationale for the Design of the
Ada® Programming Language"

[Ada '83 Rationale, HTML Version]

Copyright ©1986 owned by the United States Government. All rights reserved.
Direct inquiries to the Ada Information Clearinghouse at adainfo@sw-eng.falls-church.va.us.

CHAPTER 3: Classical Programming

3.9 If Statements

An if statement is used to select a sequence of statements for execution on the basis of a condition. The syntax

if condition then
  sequence_of_statements
else
  sequence_of_statements
end if;

is fairly classical. For nested if statements, the if and end if bracket structure avoids the dangling else ambiguity that results from not using end if. An if statement containing elsif alternatives can be used to select among several sequences of statements, depending on different conditions:

if RAIN then
  -- sequence of statements describing
  -- what to do when it rains
elsif SUN_SHINE then
  -- sequence of statements describing
  -- what to do when the sun shines
else
  -- sequence of statements describing
  -- what to do for other weather conditions
end if;

Strictly speaking, elsif alternatives are redundant: the corresponding statements can always be rewritten in the form of nested if statements. However this nesting is generally awkward and does not convey the correct impression, namely that the alternatives are on the same logical level, and this is quite apart from the fact that the conditions should be evaluated in the order in which they appear.


NEXTPREVIOUSUPTOCINDEX
Address any questions or comments to adainfo@sw-eng.falls-church.va.us.