O Level ยท Computer Science
Programming: O Level Computer Science
The tools of every program, in Cambridge pseudocode with Python beside it: variables and data types, input and output, selection and loops, strings and operators, procedures and functions, library routines, arrays and files.
- Lesson
- 11 quizzes
- Worksheet PDF
A step-by-step lesson, 11 self-marking quizzes and a printable worksheet, all on Programming for O Level.
Programming: the short answer
Every program, however large, is built from three structures: sequence, selection and iteration.
Learn it: the lesson
Programming: Loops, Subroutines, Arrays and File Handling8 steps ยท one idea at a time ยท quick check at the end ยท free to readStart the lesson โWhat the lesson covers8 steps ยท tap to see
1Variables and constants
A program needs somewhere to keep its data while it runs.
Learn this in the lesson โ2The five basic data types
Every variable has a data type.
Learn this in the lesson โ3Input and output
A program talks to its user through input and output.
Learn this in the lesson โ4Sequence and selection with IF
Every program, however large, is built from three structures: sequence, selection and iteration.
Learn this in the lesson โ5Selection with CASE
When one variable is compared with several single values, a CASE statement is shorter and clearer than a chain of IFs.
Learn this in the lesson โ6Iteration: FOR, WHILE and REPEAT
Iteration means repeating.
Learn this in the lesson โ7String handling
A string is a row of characters, and there are four routines you need for working with one: The syllabus allows the first character to be position 0 or position 1.
Learn this in the lesson โ8Arithmetic, relational and logical operators
As in maths, ^ is worked out first, then * and /, then + and โ.
Learn this in the lesson โ- Quick check: see what you remember
Programming: O Level Computer Science notes
Variables and constants
A program needs somewhere to keep its data while it runs. A variable is a named place in memory whose value can change. A constant is a named value that is fixed once it is set.
- Declare a variable by giving its identifier (its name) and its data type: DECLARE Score : INTEGER.
- Assign it a value with the arrow, read as "becomes": Score โ 0, then Score โ Score + 5.
- Declare a constant with its value: CONSTANT MaxLives โ 3. Trying to change it later is an error.
Why use a constant instead of typing 3 everywhere? If the game later allows 5 lives, you change one line, and every part of the program that uses MaxLives changes with it. Nobody has to hunt for every 3, or wonder which 3s are lives and which are something else.
Identifiers in Cambridge pseudocode use letters and digits only, start with a capital letter, and never use a keyword. In the June 2024 report the examiners reminded candidates that reserved words are not allowed as variable names.
The five basic data types
Every variable has a data type. It tells the computer how much memory to use and what can be done with the value.
Key facts
- A variable is a named place in memory whose value can change.
- Declare a variable by giving its identifier (its name) and its data type: DECLARE Score : INTEGER.
- Every variable has a data type.
- Every program, however large, is built from three structures: sequence, selection and iteration.
- A nested statement is one written inside another: an IF inside a loop, an IF inside another IF, or a loop inside a loop.
- A function works out a value and sends it back with RETURN.
Programming MCQs with answers
Tap an answer to check it.
Which data type stores a whole number?
Answer: B. Integer An integer is a whole number with no fractional part, unlike a real, a Boolean or a char.
A count-controlled loop is written with:
Answer: C. FOR โฆ NEXT A count-controlled loop repeats a set number of times, which is what FOR โฆ NEXT does; WHILE and REPEAT depend on a condition.
How many times can a WHILE loop run its body?
Answer: A. Zero or more times The condition is tested before the body runs.
What is the value of 10 - 2 * 3 ^ 2?
Answer: B. -8 Power first, then multiply, then subtract.
More questions in the 11 quizzes below โ ยท All O Level Computer Science MCQs with answers โ
Programming: common questions
What is meant by variable?
A variable is a named place in memory whose value can change. A constant is a named value that is fixed once it is set.
What is meant by nested statement?
A nested statement is one written inside another: an IF inside a loop, an IF inside another IF, or a loop inside a loop. The syllabus may ask you to use up to three levels.
What is meant by parameter?
A parameter is a value passed into the subroutine when it is called. The syllabus uses up to three parameters, each with its data type.
What is meant by global variable?
A global variable is declared in the main program. It can be used anywhere, including inside subroutines.
What is meant by local variable?
A local variable is declared inside a procedure or function. It exists only while that subroutine runs and cannot be used anywhere else.
How can I practise Programming?
Try the questions on this page, then the 11 self-marking quizzes below, which explain every answer. The worksheet gives the same practice on paper, with an answer sheet.
Practise real quizzes on this topic: 11 quizzes
Each quiz marks itself the moment it is finished and explains every answer. Start easy and work up.
- EasyProgramming: Easy 17 questionsFree, no account
- EasyProgramming: Easy 27 questions๐ Free account
- EasyProgramming, 09-265 questions๐ Free account
- EasyProgramming: easy practice, set 25 questions๐ Free account
- EasyProgramming, 10-265 questions๐ Free account
- EasyProgramming: Easy 37 questions๐ Free account
- MediumProgramming: Medium 17 questions๐ Free account
- MediumProgramming: Medium 27 questions๐ Free account
- MediumProgramming: Medium 37 questions๐ Free account
- ChallengeProgramming: Exam Style 17 questions๐ Free account
- ChallengeProgramming: Exam Style 27 questions๐ Free account
Print it: the worksheet Save to Pinterest
๐จ๏ธProgrammingCambridge pseudocode uses โ for assignment and structures such as FORโฆNEXT and IFโฆTHENโฆENDIF to express sequence, selection and iteration.See the worksheet โโฌ Download free PDFFree sample copy with a light QuizByt mark. A free account gives you more.