if
statement
There are two forms of if
statement.
if ( expression ) if ( expression ) statement and statement else statement
The interpretation of these forms are obvious. However, be careful
when another if
statement comes at the place for `statement'.
Let us examine the following example.
if ( expression1 ) if ( expression2 ) statement1 else statement2
One might guess statement2
after else
corresponds with the
first if ( expression1 )
by its appearance of indentation.
But, as a matter of fact, the Asir
parser decides that it
correspond with the second if ( expression2 )
.
Ambiguity due to such two kinds of forms of if
statement is
thus solved by introducing a rule that a statement preceded by an
else
matches to the nearest preceding if
.
Therefore, rearrangement of the above example for improving readability
according to the actual interpretation gives the following.
if ( expression1 ) { if ( expression2 ) statement1 else statement2 }
On the other hand, in order to reflect the indentation, it must be written as the following.
if ( expression1 ) { if ( expression2 ) statement1 } else statement2
Go to the first, previous, next, last section, table of contents.