Write pseudocode statements for: the assignment of values to variables

Published by Patrick Mutisya · 14 days ago

Cambridge A-Level Computer Science 9618 – 11.1 Programming Basics

11.1 Programming Basics – Assignment of \cdot alues to \cdot ariables

Objective

Write correct pseudocode statements that assign values to variables, using the appropriate syntax and respecting the rules for variable names and data types.

What is an Assignment?

An assignment stores a value in a variable. In pseudocode the assignment operator is written as :=. The general form is:

\$\text{variable} \; := \; \text{expression}\$

After the statement is executed, the variable holds the result of the expression.

Rules for \cdot ariable Names

  • Must start with a letter (A–Z or a–z).
  • Subsequent characters may be letters, digits (0–9), or an underscore (_).
  • Names are case‑insensitive in most A‑Level pseudocode conventions.
  • Do not use reserved words such as IF, FOR, WHILE, BEGIN, END.
  • Choose meaningful names that reflect the data stored (e.g., totalScore, studentName).

Data Types and Literal \cdot alues

Common data types used in A‑Level pseudocode are:

Data TypeExample LiteralDescription
Integer42Whole numbers, positive or negative.
Real3.14Numbers with a fractional part.
BooleanTRUE, FALSELogical values.
String"Hello"Sequence of characters enclosed in double quotes.

Pseudocode Syntax for Assignment

  1. Declare the variable (optional in many exam questions). Example: INTEGER totalScore.
  2. Write the assignment statement using :=.
  3. Ensure the expression on the right‑hand side is type‑compatible with the variable.

Examples of Assignment Statements

Simple \cdot alue Assignment

INTEGER age

age := 18

Arithmetic Assignment

INTEGER a, b, sum

a := 7

b := 5

sum := a + b // sum now holds 12

Using Expressions

Complex expressions can be evaluated in a single assignment:

REAL radius, area

radius := 3.5

area := 3.14159 * radius * radius // area = πr²

String Concatenation

STRING firstName, lastName, fullName

firstName := "Ada"

lastName := "Lovelace"

fullName := firstName & " " & lastName // fullName = "Ada Lovelace"

Boolean Assignment

BOOLEAN isPass

score := 78

isPass := score >= 50 // isPass becomes TRUE

Multiple Assignments in One Line (if allowed)

a, b, c := 1, 2, 3   // a=1, b=2, c=3

Common Mistakes to Avoid

  • Using the wrong operator (e.g., = instead of :=).
  • Assigning a value of the wrong type (e.g., putting a string into an integer variable).
  • Forgetting to initialise a variable before it is used in an expression.
  • Misspelling variable names – remember they are case‑insensitive but must be consistent.
  • Omitting the semicolon (;) if the exam board requires it at the end of each statement.

Practice Exercises

  1. Declare an integer variable called counter and initialise it to 0.
  2. Write a pseudocode fragment that reads a student's mark (integer) and stores TRUE in a Boolean variable passed if the mark is 40 or above.
  3. Given REAL length, width, area, assign the product of length and width to area.
  4. Create a string variable greeting that concatenates the word “Hello”, a space, and a variable name (which already holds a student's name).
  5. Using a single assignment statement, set three integer variables x, y, z to the values 10, 20, and 30 respectively.

Suggested diagram: Flow of an assignment statement – variable on the left, assignment operator in the middle, expression on the right.