Tutorial 5

Boolean Operators

0984 IGCSE


While by themselves, they are not overly useful, when used to execute specific code based on a condition (if statement) or to continue looping based on the value of a certain condition, then Boolean operators become crucial

1

All Operators

There are 3 built-in logical operators:

  • AND: both conditions must be true
  • OR: at least one condition must be true
  • NOT: inverts the condition (FALSE <-> TRUE)
OUTPUT FALSE AND FALSE OUTPUT FALSE AND TRUE OUTPUT TRUE AND FALSE OUTPUT TRUE AND TRUE OUTPUT "---" OUTPUT FALSE OR FALSE OUTPUT FALSE OR TRUE OUTPUT TRUE OR FALSE OUTPUT TRUE OR TRUE OUTPUT "---" OUTPUT NOT FALSE OUTPUT NOT TRUE

2

3 Numbers

Ask the user to enter 3 numbers and output the following information

  • If 2 or more numbers were the same
  • If all numbers were the same
  • If the numbers were entered in ascending order
  • If any number minus any other number equals the remaining number
DECLARE num1, num2, num3 : INTEGER OUTPUT "Enter number 1:" INPUT num1 OUTPUT "Enter number 2:" INPUT num2 OUTPUT "Enter number 3:" INPUT num3 OUTPUT num1 = num2 OR num1 = num3 OR num2 = num3 OUTPUT num1 = num2 AND num2 = num3 OUTPUT num1 < num2 AND num2 < num3 OUTPUT num1 - num2 = num3 OR num2 - num1 = num3 OR num1 - num3 = num2 OR num3 - num1 = num2 OR num2 - num3 = num1 OR num3 - num2 = num1