← Back to subjects
0
OCR GCSE Computer Science (J277) · Programming fundamentals
Mini-Lesson

Programming fundamentals

This mini-lesson covers OCR J277 · 2.2 Programming fundamentals: variables & constants, operators (arithmetic, comparison, Boolean), the three programming constructs (sequence, selection, iteration), data types, string manipulation, arrays, file handling, SQL and subprograms.

variables & operators the three constructs arrays, SQL subprograms programs store data and follow logical instructions

Answer the questions as you go and collect ⭐ stars. Press Start when you're ready.

Data · variables & constants

Variables, constants & data types

A program stores data in named locations:

  • Variable — a named store whose value can change while the program runs (e.g. score).
  • Constant — a named store whose value is fixed and never changes (e.g. VAT = 0.20).

Every value has a data type:

  • Integer — whole number (7)
  • Real / float — decimal number (3.14)
  • Boolean — True or False
  • Character — a single symbol ('A')
  • String — text ("hello")

Nail it: a variable changes; a constant stays the same. Choosing the right data type saves memory and prevents errors.

Quick check

Which data type?

?A program needs to store whether a light is on or off — just two possible states. Which data type is most suitable?
Operators

Operators: arithmetic, comparison & Boolean

Operators act on values:

  • Arithmetic+ − * /, plus MOD (remainder), DIV (integer/whole division) and ^ (exponent). e.g. 7 MOD 3 = 1; 7 DIV 3 = 2.
  • Comparison== equal, != not equal, <, >, <=, >=. These give a Boolean result.
  • Boolean (logical)AND, OR, NOT to combine conditions.

MOD & DIV: MOD gives the remainder, DIV gives the whole-number quotient. e.g. 17 MOD 5 = 2 and 17 DIV 5 = 3.

Calculate

Your turn — MOD

1What is the value of 17 MOD 5? (MOD gives the remainder after division)
the result
Hint: 17 ÷ 5 = 3 remainder 2, so 17 MOD 5 is the remainder.
Constructs

Sequence, selection & iteration

All programs are built from three constructs:

  • Sequence — instructions carried out one after another in order.
  • Selection — a decision: run different code depending on a condition (if…then…else, switch/case).
  • Iterationrepeating code. A for loop repeats a set number of times (count-controlled); a while loop repeats while a condition is true (condition-controlled).

Loops: use a for loop when you know how many times to repeat; use a while loop when you repeat until a condition changes.

Quick check

Which loop?

?You want to keep asking for a password until the user types the correct one (you don't know how many attempts they'll need). Which construct fits best?
Strings & arrays

String manipulation & arrays

String manipulation lets you work with text: find its length, take a substring, change case, and join (concatenate) strings.

  • e.g. length of "cat" = 3; "cat"+"dog" = "catdog".
  • Arrays store many values under one name, accessed by an index (usually starting at 0). e.g. scores[0] is the first item.
  • Arrays can be 1D (a list) or 2D (a grid/table).

Watch the index: most arrays start at index 0, so an array of 5 items has indexes 0–4.

Calculate

Your turn — array index

2An array names holds 6 items and is indexed from 0. What is the index of the last item?
index
Hint: with 6 items starting at 0, indexes run 0 to (6−1).
Sort it

Which construct?

Tap a code idea, then tap which construct it uses.

➡️ Sequence

🔀 Selection

🔁 Iteration

Files, SQL & subprograms

File handling, SQL & subprograms

Three more essentials:

  • File handling — programs can open, read, write and close text files to store data permanently.
  • SQL — used to search a database. SELECT columns FROM a table WHERE a condition is true (e.g. SELECT name FROM pupils WHERE age > 15).
  • Subprograms — named blocks of reusable code. A procedure carries out a task; a function also returns a value. They make code shorter, clearer and reusable.

Procedure vs function: a function returns a value; a procedure just does a job. SQL SELECT…FROM…WHERE retrieves matching records.

Quick check

Read the SQL

?What does SELECT name FROM pupils WHERE age > 15 return?
Quick check

Procedure vs function

?What is the key difference between a function and a procedure?
Match it

Match term to meaning

Tap a term on the left, then its matching description on the right.

Term
Meaning
Recap

The big ideas to know

Variable value changes · constant value fixed

Data types: integer · real/float · Boolean · character · string

Operators: arithmetic (+ − * / MOD DIV) · comparison (== != < >) · Boolean (AND OR NOT)

Constructs: sequence · selection (if) · iteration (for = known count, while = condition)

Arrays: many values, one name, indexed from 0 (1D & 2D)

SQL: SELECT…FROM…WHERE · subprograms: procedure (does a job) vs function (returns a value)

You've covered the whole topic. Press Finish to see your score.

🏆

Mini-lesson complete!

⭐⭐⭐

You've worked through Programming fundamentals for OCR GCSE Computer Science (J277). 🎉

Your stars: 0 / 0

Next: test yourself in the Evaluate stage Confidence Quiz, then lock it in with Verify.

📣 Smashed it? Share your score

Challenge a mate to beat your stars, or show a parent how you got on.

→ Back to all subjects