The logical operators are:
Examples:
if ( A or "Rest of condition" )
S1
else
S2
Rest of the program
is execute as follows:
1. evaluate A
2. if TRUE then execute S1 and proceed to "Rest of the program"
3. if FALSE then CONTINUE with the evaluation of
the "Rest of condition"
3a. if "Rest of condition" is TRUE,
then execute S1 and proceed to "Rest of the program"
3b. if "Rest of condition" is FALSE,
then execute S2 and proceed to "Rest of the program"
|
if ( A and theRest ) ----> |
statement1; V
else +--------------+ FALSE
statement2; | eval A |-----------------+
+--------------+ |
| (TRUE) |
| |
V |
+--------------+ FALSE |
| eval theRest |------------+ |
+--------------+ | |
| (TRUE) | |
| | |
V | |
statement1 | |
| | |
+---------+ | |
| | |
| | |
| statement2 <-------------+----+
| |
| |
+-------->+
|
|
V
|
Evaluate "A" (CMP)
FALSE
Branch on FALSE (!!!) outcome of "condition" to here (A:) --------+
| (TRUE) |
| |
V |
Evaluate "theRest" (another CMP) |
FALSE |
Branch on FALSE (!!!) outcome of "theRest" to here (B:) ----------+
| (TRUE) |
| |
V |
A: "statement1" assembler code |
| |
Branch always to there (B:) -------------+ |
| |
| |
"statement2" assembler code <---------|----------------------+
| |
V |
C: +<-------------------------------+
|
V
|
int x, y, a;
if (a <= x and x <= b)
x = x + 1;
else
x = x - 1;
The flow chart of the above program is:
|
Assembler program for this compound if-statement: click here