Complex condition checks#

Sometimes you can combine conditions with AND instead of nesting if statements#

Gpa ← 0.9
LowestGrade ← 0.75

IF Gpa >= 0.85
  THEN
    IF LowestGrade >= 0.7
      THEN
        OUTPUT "Well done"
    ENDIF
ENDIF

IF Gpa >= 0.85 AND LowestGrade >= 0.7
  THEN
    OUTPUT "Well done"
ENDIF

How AND statements are processed#

First Condition

Second Condition

Condition evaluates as

TRUE

TRUE

TRUE

TRUE

FALSE

FALSE

FALSE

TRUE

FALSE

FALSE

FALSE

FALSE

If you need to remember the results of a condition check later in your code, use Boolean variables as flags#

Gpa ← 0.9
LowestGrade ← 0.75
HonourRoll ← FALSE

IF Gpa >= 0.85 AND LowestGrade >= 0.7
  THEN
    HonourRoll ← TRUE
  ELSE
    HonourRoll ← FALSE
ENDIF

// Somewhere later in your code
IF HonourRoll
  THEN
    OUTPUT "Well done"
ENDIF

Combining operators allows you to handle complex business rules in your code but must be tested very carefully to avoid introducing errors#