Form 3 · Chapter 4

Coding Structure

Variables, data types, operators and control structures: the building blocks of code.

Every program is built from a few basic building blocks: variables, data types, operators and control structures. Understanding them lets you read and write code.

Variables and data types

A variable is a named storage location that holds a value which can change while the program runs, for example score = 10. The data type tells the computer what kind of value a variable holds:

  • Integer — whole numbers, such as 15.
  • Float — numbers with decimals, such as 3.14.
  • String — text, such as "Ali".
  • Boolean — only true or false.

Key idea

Operators act on values. Arithmetic operators (+ - * /) do maths; relational operators (> < ==) compare values and give a true/false result.

Control structures

Control structures decide the order in which lines run: sequence (line by line), selection (an IF chooses a path), and repetition (a loop repeats lines). These are the same three structures used in algorithms.

Example

age = 15
IF age >= 13 THEN
  OUTPUT "Teenager"
ENDIF

Here age is an integer variable, >= is a relational operator, and the IF is a selection control structure.

Choosing the right data type matters: storing a price as an integer would lose the cents, while storing it as a float keeps them. Picking suitable variables, data types and structures keeps a program correct, efficient and easy for others to understand. These same building blocks appear in every programming language you will ever learn, from Python to C, so mastering them now makes learning any new language far easier later on.

Stuck on this topic? A verified JomKelas tutor can walk you through it.

Find a verified tutor