Handling multiple conditions#

You may need to check multiple conditions to determine the correct action#

Province ← "Ontario"

IF Province = "Alberta"
  THEN
    Tax ← 0.05
ENDIF
IF Province = "Nunavut"
  THEN
    Tax ← 0.05
ENDIF
IF Province = "Ontario"
  THEN
    Tax ← 0.13
ENDIF

OUTPUT "Tax is ", Tax

If multiple conditions cause the same action they can be combined into a single condition#

Province ← "Nunavut"

IF Province = "Alberta" OR Province = "Nunavut"
  THEN
    Tax ← 0.05
ENDIF
IF Province = "Ontario"
  THEN
    Tax ← 0.13
ENDIF

OUTPUT "Tax is ", Tax

How OR statements are processed#

First Condition

Second Condition

Condition evaluates as

TRUE

TRUE

TRUE

TRUE

FALSE

TRUE

FALSE

TRUE

TRUE

FALSE

FALSE

FALSE

If an action depends on a combination of conditions you can nest if statements#

Country ← "Canada"
Province ← "Nunavut"

IF Country = "Canada"
  THEN
    IF Province = "Alberta" OR Province = "Nunavut"
      THEN
        Tax ← 0.05
    ENDIF
    IF Province = "Ontario"
      THEN
        Tax ← 0.13
    ENDIF
  ELSE
    Tax ← 0.0
ENDIF

OUTPUT "Tax is ", Tax

Handling real world business rules may require complicated conditional logic, but the code can still be written efficiently#

  • Apply appropriate state or federal taxes based on location

  • Calculate salary based on job level