8.1

Topic 8

Programming concepts

  • IGCSE Computer science 0478
  • 7 min read
  • Syllabus 2026, 2027 and 2028

Objectives

  1. 1

    Declare and use variables and constants

  2. 2

    Understand and use basic data types

  3. 3

    Understand and use input and output

  4. 4

    • aUnderstand and use the concept of sequence
    • bUnderstand and use the concept of selection
    • cUnderstand and use the concept of iteration
    • dUnderstand and use the concepts of totalling and counting
    • eUnderstand and use the concept of string handling
    • fUnderstand and use arithmetic, relational and logical operators
  5. 5

    Understand and use nested statements

  6. 6

    • aUnderstand what is meant by procedures, functions and parameters
    • bDefine and use procedures and functions, with or without parameters
    • cUnderstand and use local and global variables
  7. 7

    Understand and use library routines

  8. 8

    Understand how to create a maintainable program

Cambridge IGCSE Computer Science 0478 syllabus 2026-2028, 8.1 Programming concepts (copied for internal use as permitted by Cambridge)

Detailed · Deep study

1Variables, constants and data types

variable

A named memory location that stores a value which can change while the program is running.

constant

A named memory location that stores a value which cannot change while the program is running.

Data typeStoresExample
INTEGERa whole number42, −3
REALa number with a fractional part4.7, −0.5
CHARa single character'A', '@'
STRINGa sequence of zero or more characters"Hello", ""
BOOLEANTRUE or FALSETRUE
DECLARE Counter : INTEGER
DECLARE Price : REAL
DECLARE Initial : CHAR
DECLARE FirstName : STRING
DECLARE GameOver : BOOLEAN
CONSTANT VAT ← 0.2
Counter ← 0
Price ← 12.50
GameOver ← FALSE
Declaring variables and constants, then assigning values with ←.

2Input and output

OUTPUT "Enter your name"
INPUT FirstName
OUTPUT "Hello ", FirstName, ", you have ", Lives, " lives left"
INPUT and OUTPUT; several values can be output separated by commas.

3Sequence, selection and iteration

Sequence: statements are carried out one after another, in order. The order matters – e.g. a total must be set to 0 before values are added.

Selection: a decision chooses which statements run. Use IF for conditions and ranges; use CASE to choose between several single values.

IF Mark >= 50
  THEN
    OUTPUT "Pass"
  ELSE
    OUTPUT "Fail"
ENDIF
IF … THEN … ELSE … ENDIF.
INPUT Choice
CASE OF Choice
  1 : OUTPUT "New game"
  2 : OUTPUT "Load game"
  3 : OUTPUT "Quit"
  OTHERWISE OUTPUT "Invalid choice"
ENDCASE
CASE OF … OTHERWISE … ENDCASE chooses one branch from the value of a variable.

Iteration: statements are repeated.

LoopPseudocodeUse when
count-controlledFOR … TO … NEXTthe number of repeats is known
pre-conditionWHILE … DO … ENDWHILErepeats while a condition is true; tested first, so may run 0 times
post-conditionREPEAT … UNTILrepeats until a condition is true; tested at the end, so runs at least once (e.g. validation)
FOR Count ← 1 TO 10
    OUTPUT Count * 5
NEXT Count

FOR Count ← 10 TO 0 STEP -2
    OUTPUT Count
NEXT Count
Count-controlled loops: the 5 times table, then a countdown in steps of 2.
INPUT Number
WHILE Number <> -1 DO
    Total ← Total + Number
    INPUT Number
ENDWHILE
Pre-condition loop: the condition is tested first, so the loop may not run at all.
REPEAT
    OUTPUT "Enter the password"
    INPUT Password
UNTIL Password = "Secret"
Post-condition loop: always runs at least once.

4Totalling and counting

Total ← 0
Count ← 0
FOR Index ← 1 TO 20
    INPUT Temperature
    Total ← Total + Temperature            // totalling
    IF Temperature > 30
      THEN
        Count ← Count + 1                  // counting
    ENDIF
NEXT Index
OUTPUT "Total ", Total, "; days above 30: ", Count
Totalling and counting inside a loop.

5String handling

OperationReturns
LENGTH(String)the number of characters
SUBSTRING(String, Start, Length)part of the string, starting at position Start
UCASE(String)the string in upper case
LCASE(String)the string in lower case
Word ← "Computer"
OUTPUT LENGTH(Word)                  // 8
OUTPUT SUBSTRING(Word, 1, 4)         // "Comp"
OUTPUT UCASE(Word)                   // "COMPUTER"
OUTPUT LCASE(Word)                   // "computer"
String handling (first character at position 1).

6Operators

TypeOperators
arithmetic+ − * / ^ (raised to the power of) MOD (remainder) DIV (whole-number division)
relational= < <= > >= <> (not equal to) – the result is always TRUE or FALSE
logicalAND (both true) OR (at least one true) NOT (reverses)

Worked example

Evaluate expressions

Find the values of DIV(23, 4), MOD(23, 4), 2 ^ 3 and (5 > 3) AND NOT (2 = 2).

  1. 1

    23 ÷ 4 = 5 remainder 3.

    DIV gives 5, MOD gives 3

  2. 2

    2 × 2 × 2.

    8

  3. 3

    TRUE AND NOT TRUE = TRUE AND FALSE.

    FALSE

Answer5, 3, 8, FALSE

7Nested statements

A nested statement is one inside another: selection inside a loop, a loop inside a loop, or an IF inside an IF. You will not have to write more than three levels.

FOR Row ← 1 TO 3
    FOR Column ← 1 TO 4
        IF Row = Column
          THEN
            OUTPUT "*"
          ELSE
            OUTPUT "-"
        ENDIF
    NEXT Column
NEXT Row
Nested statements: selection inside iteration inside iteration (three levels).

8Procedures, functions and parameters

procedure

A named block of code (subroutine) that carries out a task; it is called by name and does not return a value.

function

A named block of code (subroutine) that carries out a task and returns a single value to the point where it was called.

parameter

A value passed into a procedure or function when it is called (up to three in exam questions).

PROCEDURE Stars(Number : INTEGER)
    DECLARE Count : INTEGER             // local variable
    FOR Count ← 1 TO Number
        OUTPUT "*"
    NEXT Count
ENDPROCEDURE

FUNCTION Area(Length : REAL, Width : REAL) RETURNS REAL
    RETURN Length * Width
ENDFUNCTION

CALL Stars(5)
OUTPUT "Area = ", Area(4.5, 2.0)
A procedure is called with CALL; a function returns a value and is used in an expression.
Local variableGlobal variable
declaredinside a procedure or functionin the main program, outside any subroutine
scopecan only be used in that subroutinecan be used anywhere in the program
lifetimeexists only while the subroutine runsexists while the whole program runs

Local variables avoid accidental changes from other parts of the program and save memory; subroutines can be reused and tested separately.

9Library routines

A library routine is a pre-written, tested subroutine built into the language that can be used in any program.

RoutineReturns
MOD(a, b)the remainder when a is divided by b
DIV(a, b)the whole-number quotient, with the fractional part discarded
ROUND(x, places)x rounded to the given number of decimal places
RANDOM()a random number between 0 and 1 inclusive
OUTPUT DIV(17, 5)                    // 3  (whole-number quotient)
OUTPUT MOD(17, 5)                    // 2  (remainder)
OUTPUT ROUND(3.14159, 2)             // 3.14
Dice ← ROUND(RANDOM() * 5, 0) + 1    // whole number from 1 to 6
Library routines.

10Maintainable programs

A maintainable program is easy for another programmer to understand, correct and update. It uses: meaningful identifiers for variables, constants, arrays, procedures and functions (e.g. TotalCost, not T); comments to explain what the code does; and procedures and functions to split the code into manageable parts.

// Calculates the total cost of an order, including VAT
CONSTANT VATRate ← 0.2
DECLARE NetCost : REAL
DECLARE TotalCost : REAL
INPUT NetCost
TotalCost ← NetCost * (1 + VATRate)      // add VAT
OUTPUT "Total cost: ", ROUND(TotalCost, 2)
A maintainable program: comments, a named constant and meaningful identifiers.
Pseudocode and Python compared.
PseudocodePython
DECLARE Count : INTEGERcount = 0 (no declarations)
X ← 5x = 5
INPUT Namename = input()
OUTPUT "Hi ", Nameprint("Hi", name)
IF … THEN … ELSE … ENDIFif …: / else:
FOR I ← 1 TO 10 … NEXT Ifor i in range(1, 11):
WHILE … DO … ENDWHILEwhile …:
MOD(a, b) / DIV(a, b)a % b / a // b

11Exam focus

Key words: variable; constant; data type; sequence; selection; iteration; count-controlled; pre-condition; post-condition; totalling; counting; string handling; operator; nested; procedure; function; parameter; local; global; library routine; maintainable.

Quick self-check

Answer in your head first, then reveal.

  1. INTEGER (1); REAL (1); BOOLEAN (1).

  2. Pre-condition tests the condition before the loop so it may not run (1); post-condition tests at the end so it runs at least once (1).

  3. "xam" (1).

  4. A function returns a value (1); a procedure does not / is called with CALL (1).

  5. Any two: meaningful identifiers; comments; procedures/functions; constants (2).

Finished this subtopic? Track it on your subject page.