Categories: All Variables and Constants  String manipulation  Builtin functions  Input and output  Arrays  Conditional logic  Repetition / Iteration  Functions / Procedures 

Show:

This resource is designed as a quick revision guide and must not be used by students during a NEA where internet access is not allowed. It has not been endorsed by any exam boards. If you spot any mistakes, please let me know and I'll fix them asap.

Conditional logic

Logic is the ability to make decisions. Conditional logic means making decisions based on clearly defined conditions, e.g. If the starting gun for a race has been fired then start running, else (otherwise) keep waiting.

Top tips:

  • Think carefully about the decisions your program will have to make
    You can compare data using the greater than > operator or the less than < operator. 
  • Be careful when checking if two values are equal
    In VB.NET you use one equals sign (=) to both set a value and test if two values are the same.
    In python you use one equals sign (=) to set a value and two equals signs to test if two values are the same.
IF statement
   

If you want your code to make a decision you'll need an IF statement.

This example asks the user how old they are and checks that they've entered a number bigger than 0

RECEIVE age FROM (INTEGER) KEYBOARD IF age < 0 THEN SEND "You can't be less than 0 years old!" ENDIF
Dim age As Integer age = Convert.Int32(InputBox("How old are you?")) If age < 0 Then MsgBox("You can't be less than 0 years old!") End If
age = int(input("How old are you?")) if age < 0: print("You can't be less than 0 years old!")
age = int(input("How old are you?")) if age < 0 then print("You can't be less than 0 years old!") endif
{ user input not specified in eduqas pseudocode reference } age is integer output "How old are you?" set age = input if age < 0 then output "You can't be less than 0 years old!" end if
IF ... ELSE statement
   

If you want your code to choose between two possibilities you'll need an IF ... ELSE statement.

This example asks the user what their name is. If they answer the question it says hello. If they don't answer the question it displays an error message.

SEND "What's your name?" TO DISPLAY RECEIVE name FROM (STRING) KEYBOARD IF name = "" THEN SEND "You have to enter your name" TO DISPLAY ELSE SEND "HELLO " & name TO DISPLAY END IF
Dim name As String name = InputBox("What is your name?") If name = "" Then MsgBox("You have to enter your name") Else MsgBox("Hello " & name) End If
name = input("What is your name?") if name == "": print("You have to enter your name") else: print("Hello " + name)
name = input("What is your name?") if name == "" then print("You have to enter your name") else print("Hello " + name) endif
{ user input not specified in eduqas pseudocode reference } output "What is your name?" name is string set name = input if name == "" then output "You have to enter your name" else output "Hello " + name end if
Not equal to
   

You can test if two expressions are the same using the equal to or not equal to operator.

An expression can be a variable or combination of variables & data (e.g. 1 + 1)

An operator is a symbol that means add, subtract or something similar.

This example asks the user to enter a temperature  of a bath (in degrees Celsius) and then follows the following rules:

Equal to 37 degrees: says "Perfect - that's body temperature"

Not equal to 37 degrees: "Not body temperature"

SEND "What's the temperature of the bath?" TO DISPLAY RECEIVE temperature FROM (INTEGER) KEYBOARD IF temperature = 37 THEN SEND "Perfect - that's body temperature" TO DISPLAY END IF IF temperature <> 37 THEN SEND "Not body temperature" TO DISPLAY END IF
Dim temperature As Integer temperature = InputBox("What's the temperature of the bath?") If temperature = 37 Then MsgBox("Perfect - that's body temperatuyre") End If If temperature <> 37 Then MsgBox("Not body temperature") End If
temperature = int(input("What's the temperature of the bath?") if temperature == 37: print("Perfect - that's body temperature") if temperature != 37: print("Not body temperature")
temperature = int(input("What's the temperature of the bath?") if temperature == 37 then print("Perfect - that's body temperature") endif if temperature != 37 then print("Not body temperature") endif
{ user input not specified in eduqas pseudocode reference } output "What's the temperature of the bath?" temperature is integer temperature = input if temperature == 37 then output "Perfect - that's body temperature" end if if temperature <> 37 then output "Not body temperature" end if
Greater than or less than
   

If you need to compare two expressions you will need the greater than or less than operators.

An expression can be a variable or combination of variables & data (e.g. 1 + 1)

An operator is a symbol that means add, subtract or something similar.

This example asks the user to enter a password and displays how strong that password is based purely on the length:

Less than 5 characters: weak

More than or equal to 8 characters: strong

Otherwise: medium

SEND "Please enter a password" TO DISPLAY RECEIVE password FROM (STRING) KEYBOARD IF LENGTH(password) >= 8 THEN SEND "strong" TO DISPLAY ELSE IF LENGTH(password) < 5 THEN SEND "weak" TO DISPLAY ELSE SEND "medium" TO DISPLAY END IF END IF
Dim password As String password = InputBox("Please enter a password") If Len(password) >= 8 Then MsgBox("strong") Else If Len(password) < 5 Then MsgBox("weak") Else MsgBox("medium") End If End If
password = input("Please enter a password") if len(password) >= 8: print("strong) else: if len(password) < 5: print("weak") else: print("medium")
password = input("Please enter a password") if password.length >= 8 then print("strong) else if password.length < 5 then print("weak") else print("medium") endif endif
{ user input not specified in eduqas pseudocode reference } { neither is string length... } output "Please enter a password" password is string set password = input if password.length >= 8 then output "strong else if password.length < 5 then output "weak" else output "medium" end if end if

Loading...