CS255 Syllabus

# Compound condition with OR

• Program control of the if-statement with an compound condition "A or theRest":

 ``` if ( A or theRest ) ----> | statement1; V else +--------------+ TRUE statement2; | eval A |--------+ +--------------+ | | | | FALSE | V | +--------------+ FALSE | | eval theRest |--------|---+ +--------------+ | | | TRUE | | | | | V | | statement1 <---------+ | | | +---------+ | | | | +--------------------+ | | | V | statement2 | | | | +-------->+ | | V ```

• If A is true, then A or "something" is also true, regardless what the "something" evaluates to.

• Therefore, we can branch (jump) to the then-part as soon as we find that A is true.

• Assembler construct that realizes the control flow of the if-statement with an compound condition "A or theRest" is as follows:

 ``` Evaluate "A" (CMP) TRUE Branch on TRUE (!!!) outcome of "condition" to here (A:) ---+ | | | FALSE | 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 (C:) -------------+ | | | | | B: "statement2" assembler code <---------|----------------------+ | | V | C: +<-------------------------------+ | V ```

• Example:

```   int x, y, a;

if (x <= a || x >= b)
x = x + 1;
else
x = x - 1;
```

The flow chart of the above program is: