Programming Concepts

2026 Syllabus Objectives

By the end of this topic, you should be able to:

  1. Declare and use variables and constants
  2. Understand and use basic data types (integer, real, char, string, Boolean)
  3. Understand and use input and output
  4. Understand and use:
    • (a) Sequence
    • (b) Selection (IF statements, CASE statements)
    • (c) Iteration (count-controlled loops, pre-condition loops, post-condition loops)
    • (d) Totalling and counting
    • (e) String handling (length, substring, upper, lower)
    • (f) Arithmetic, relational and logical operators
  5. Understand and use nested statements (nested selection and iteration, up to 3 levels)
  6. Understand procedures, functions and parameters; define and use them; understand local and global variables
  7. Understand and use library routines (MOD, DIV, ROUND, RANDOM)
  8. Understand how to create a maintainable program

1. Variables and Constants

What is a Variable?

A variable is a named storage location in a computer's memory that holds a value. Think of it like a labeled box where you can store information. The important thing about variables is that the value inside them can change while your program is running.

Rules for naming variables:

  • Use mixed case (start with a capital letter, like MyAge or PlayerScore)
  • Only use letters (A-Z, a-z) and digits (0-9)
  • Must start with a letter, not a digit
  • Make the name meaningful so you know what it stores

How to declare a variable:

In pseudocode:

DECLARE <identifier> : <datatype>

Examples:

DECLARE Age : INTEGER
DECLARE Price : REAL
DECLARE GameOver : BOOLEAN

In Python:

score = int()      # whole number
cost = float()     # decimal number
light = bool()     # True or False value

When you declare a variable, the computer sets aside memory space for it based on the data type you specify.

What is a Constant?

A constant is like a variable, but its value is set once and never changes during the program. Constants are useful for values that should stay the same throughout your program, like the value of pi (3.142) or a password.

Rules for naming constants:

  • Use ALL UPPERCASE letters (like PI or PASSWORD)
  • This makes it easy to see that it's a constant, not a variable

Why use constants?

  • They make your code easier to read and understand
  • If you need to change the value later, you only need to change it in one place
  • They prevent accidental changes to important values

How to declare a constant:

In pseudocode:

CONSTANT <identifier> ← <value>

Examples:

CONSTANT PI ← 3.142
CONSTANT PASSWORD ← "letmein"
CONSTANT HIGHSCORE ← 9999

In Python:

PI = 3.142
VAT = 0.20
PASSWORD = "letmein"

Note: Python doesn't have a special way to declare constants, but programmers use uppercase names to show that a value shouldn't be changed.

Sign in to view full notes