Control Structure – SS2 Digital Technologies Lesson Note (Second Term)
Download this term · ₦1,000Lesson note at a glance
- Subject
- Digital Technologies
- Class
- SS2
- Term
- Second Term
- Topic
- Control Structure
- Order
- Topic 4 of 8 this term
- Reading time
- 6 min
A control structure is a part of a program that decides which lines of code run and how many times they run.
- If-else statement: makes decisions.
- Loop: repeats a block of code.
- Function: saves a block of code so it can be reused.
The examples in this lesson use Python.
Behavioural objectives
- Explain what a control structure is and why programs need them.
- Write a simple if-else statement in Python.
- State the difference between a for loop and a while loop.
- Define a function and call it with different inputs.
- Identify common Python mistakes such as a missing colon, bad indentation and an infinite loop.
Why do programs need control structures?
Programs need control structures because real programs must make choices and repeat tasks, not just run from the top line to the bottom line.
- If-else: answers a question such as “Should I let this user log in?”
- Loops: handle a task such as “Should I send this email to all 500 students?”
- Functions: handle a task such as “Should I do this calculation again and again?”
Control structures are the “traffic wardens” of your code. They tell the computer when to stop, when to turn and when to go back and repeat something.
What is an if-else statement?
An if-else statement is a control structure that makes the computer choose between two actions, depending on whether a condition is true.
- Real-life logic: “If I have money, I will buy lunch. Else (otherwise), I will drink water.”
- If: runs its action when the condition is true.
- Else: runs its action when the condition is false.
How is an if-else statement written in Python?
| Line | Code | Indentation |
|---|---|---|
| 1 | score = 65 | None |
| 2 | if score >= 50: | None |
| 3 | print(“You Passed!”) | 4 spaces |
| 4 | else: | None |
| 5 | print(“Try again next time.”) | 4 spaces |
- Output: “You Passed!”, because 65 is greater than or equal to 50.
Key points
- The condition: the question being asked, for example score >= 50. It is either true or false.
- The indentation: the gap before print shows that the action belongs to that choice.
- The colon: the if line and the else line both end with a colon.
What are loops?
A loop is a control structure that tells the computer to repeat a block of code.
- Why it helps: writing “I will not talk in class” 100 times by hand is tiring, but a computer does not get tired.
- Two main kinds: the for loop and the while loop.
What is a for loop?
A for loop repeats a block of code a known number of times, once for each item in a sequence.
- Use it when: you know how many times to repeat.
- Everyday example: “For every student in this class, give them a textbook.”
| Line | Code | Indentation |
|---|---|---|
| 1 | for number in range(1, 6): | None |
| 2 | print(number) | 4 spaces |
- Output: the numbers 1, 2, 3, 4 and 5, each on its own line.
- Note on range: range(1, 6) starts at 1 and stops before 6.
What is a while loop?
A while loop repeats a block of code for as long as its condition stays true.
- Use it when: you repeat until a specific event happens.
- Everyday example: “Keep playing the music while the battery is above 10%.”
| Line | Code | Indentation |
|---|---|---|
| 1 | count = 1 | None |
| 2 | while count <= 5: | None |
| 3 | print(count) | 4 spaces |
| 4 | count = count + 1 | 4 spaces |
- Output: the numbers 1 to 5.
- Line 4: changes the condition each time, so the loop can end.
What is the difference between a for loop and a while loop?
| Point | For loop | While loop |
|---|---|---|
| Repeats | A known number of times | Until a condition becomes false |
| Nickname | The counter | The watchman |
| Example | Printing a timetable | Running a game until “Game Over” |
What is a function?
A function is a named block of code that performs a specific task and can be used again whenever it is needed.
- Reusable recipe: write the 10 lines for a student’s grade once, give them a name and call the name each time.
- Parameter: a name inside the brackets that receives the input, such as name below.
- Calling a function: writing its name with brackets to make it run.
- Return value: a result the function sends back after its work.
How is a function like a blender?
- Define it: you build the blender (the function).
- Input: you put in fruit (the data or parameters).
- Process: the blender spins (the code runs).
- Output: you get juice (the return value).
What does a Python function look like?
| Line | Code | Indentation |
|---|---|---|
| 1 | def welcome_student(name): | None |
| 2 | print(“Hello ” + name + “, welcome to the Computer Lab!”) | 4 spaces |
| 3 | # To use it, you just call the name: | None |
| 4 | welcome_student(“Bisi”) | None |
| 5 | welcome_student(“Obi”) | None |
- Output line 1: Hello Bisi, welcome to the Computer Lab!
- Output line 2: Hello Obi, welcome to the Computer Lab!
- Same code, different input: the function ran twice with two different names.
Which control tool should I use?
| Tool | Human meaning | When to use it |
|---|---|---|
| If-else | “Only do this if…” | Checking passwords or grades. |
| For loop | “Do this X times.” | Printing a list or a timetable. |
| While loop | “Do this until…” | Running a game until “Game Over”. |
| Function | “Save this task for later.” | Calculating tax or cleaning data. |
What mistakes should I avoid?
The three common Python mistakes are a missing colon, bad indentation and an infinite loop.
- Forgetting the colon (:): every if, else, for, while and def line must end with a colon, like a full stop at the end of a sentence.
- Bad indentation: if code is not lined up correctly, the computer cannot tell which code belongs to which block.
- The infinite loop: a while loop whose condition never becomes false, such as while 1 < 2, keeps running until you stop the program.
What can students practise in the class lab?
- The Bouncer: write a program that asks for a user’s age. If the age is under 13, print “You are too young for Facebook.” Else, print “Welcome!”
- The Multiplier: use a for loop to print the 5 times table (5, 10, 15 and so on up to 60). Hint: multiply 5 by each number from 1 to 12.
- The Shortcut: create a function called calculate_area that takes the length and width of a room and shows its size.
Evaluation
- What is a control structure?
- What is the job of the condition in an if-else statement?
- State one difference between a for loop and a while loop.
- What is a function, and why is it useful?
- Name two mistakes that can stop a Python program from working correctly.
Assignment
In your notebook, explain the blender comparison for a function in your own words. Then give one example of when you would use each of these: an if-else statement, a for loop and a while loop.
This term's Digital Technologies topics
SS2 Second Term · 8 topics
Get Digital Technologies as PDF and Word
Every week of SS2 Digital Technologies, Second Term, formatted and ready to print. Ad-free, and the copy lock comes off.
Get this term Card, bank transfer, USSD or OPay

