Hiring Partners
Segilola Resources Operating LimitedTaviatech TechnologiesFCMBMTN NigeriaAdvans La Fayette Microfinance BankAboki AfricaFirst Bank of NigeriaOPay
โ† Programming Logic for Web Developers ยท Lesson 3 of 4

How Programs Make Decisions

๐Ÿ“– Every lesson in this course is free to read right here, no account needed. Create a free account to track your progress, take the exam, and earn your certificate.
3
Module 2 ยท Making Decisions and Repeating Tasks

โฌ… Back to Course Outline

๐Ÿ”€ Module 2 โ€” Making Decisions and Repeating Tasks

Programming Logic for Web Developers ยท Beginner Level ยท 2026


1. Module Introduction

Welcome to Module 2. In Module 1, you learned how to think in steps. You learned what an algorithm is. You learned how to draw flowcharts and write pseudocode. Those are the foundations of programming logic.

Now we go one step further. Programs do not just follow steps in a straight line. They also make choices. They also repeat actions. Imagine a game that asks, "Do you want to play again?" If you say yes, it repeats. If you say no, it stops. That is a decision and a repetition.

In this module, you will learn how programs make decisions. You will learn about if, else, and else if. You will learn about true and false. You will also learn how programs repeat tasks using loops.

Do not worry if these words sound new. Every word will be explained in simple language. You will see examples from real life, from school, from home, and from Nigeria. You will also draw flowcharts and write pseudocode for decisions and loops.

This module is written for beginners. You do not need a computer. You just need your brain and a notebook. Let us begin.

    YOUR LEARNING JOURNEY IN MODULE 2
    =================================

    [ Start ]
        |
        V
    What is a Decision?
        |
        V
    True and False
        |
        V
    If Statements
        |
        V
    Else Statements
        |
        V
    What is a Loop?
        |
        V
    Repeat Loops
        |
        V
    While and For Loops
        |
        V
    [ You can now write programs that decide and repeat! ]
    

Summary of the Introduction

This module teaches you how programs make decisions and repeat tasks. You will learn about if, else, true and false, and loops. Everything is explained in simple language with examples.


2. Learning Objectives

By the end of this module, you will be able to:

  1. Explain what a decision is in a program.
  2. Describe what true and false mean.
  3. Use simple comparisons like equal, greater than, and less than.
  4. Write simple if statements in pseudocode.
  5. Add else and else if to handle more options.
  6. Draw a flowchart with a decision diamond.
  7. Explain what a loop is and why loops are useful.
  8. Write simple repeat loops in pseudocode.
  9. Understand while loops and for loops.
  10. Spot decisions and repetitions in daily life.

Summary of Learning Objectives

You will learn how to write decisions (if, else) and repetitions (loops). You will also learn true and false, comparisons, and how to draw flowcharts with decisions.


3. Warm-up Story โ€” Chidi and the Smart Gate

Chidi is a 12-year-old boy who lives in Abuja. One day, his school installed a new gate. It was a smart gate. It opened by itself.

Chidi was curious. He watched the gate carefully.

When a teacher walked close, the gate opened. When a student walked close, the gate opened. But when a stranger walked close, the gate stayed closed.

"How does it know?" Chidi asked the security guard.

"It uses a sensor," the guard said. "If the person has a school ID card, the gate opens. Else, the gate stays closed."

Chidi thought about it. "So it makes a decision?"

"Yes," the guard said. "It checks: Is there an ID card? If yes, open. If no, stay closed."

Chidi was amazed. He noticed something else. The gate did not open just once. It opened for every person who had an ID card. It repeated the decision again and again.

"It also repeats!" Chidi said.

"Exactly," the guard said. "It makes a decision, then repeats. That is how most programs work."

From that day, Chidi understood. Programs make decisions and repeat tasks. That is what this module is all about.

    CHIDI AND THE SMART GATE
    ========================

    [ Person walks close ]
              |
              V
    [ Gate checks: Does person have ID? ]
       /                          \
     Yes                          No
      |                            |
      V                            V
    [ Open gate ]              [ Stay closed ]

    Then the gate repeats this for the next person.
    

Summary of the Warm-up Story

Chidi learned that the smart gate makes a decision (open or close) and repeats it for every person. This story introduces decisions and loops.


4. Main Lessons

In this section, you will go through 12 short lessons. Each lesson teaches one big idea. Each lesson ends with a mini summary. Read slowly. Think about the examples. Ask questions. That is how you learn.

Lesson 1 โ€” What is a Decision?

Definition

A decision is a choice between two or more options. In a program, a decision lets the program choose what to do based on a condition.

Why it is important

Without decisions, programs would always do the same thing. They could not react to different situations. Decisions make programs smart.

Simple explanation

Think of walking to school. If it is raining, you take an umbrella. If it is not, you do not. That is a decision.

Real-life example

An ATM makes a decision. If your PIN is correct, it gives you money. If it is wrong, it asks you to try again.

School example

A teacher makes a decision. If a student passes, they move to the next class. If they fail, they repeat.

Home example

Your mother makes a decision. If there is rice at home, she cooks rice. If not, she cooks something else.

Nigerian example

A fuel station makes a decision. If there is fuel in the tank, it sells. If not, it tells customers to wait.

Illustration

    A SIMPLE DECISION
    =================

    [ Is it raining? ]
       /           \
     Yes            No
      |              |
      V              V
    [ Take        [ Do not
      umbrella ]    take umbrella ]
        

Mini summary

A decision is a choice between options. Programs use decisions to react to different situations.


Lesson 2 โ€” True and False

Definition

True and false are the two possible answers to a yes-or-no question. In programming, they are called Boolean values.

Why it is important

Every decision in a program is based on something being true or false. Without true and false, decisions would not work.

Simple explanation

Think of a light switch. It is either ON or OFF. True is like ON. False is like OFF.

Real-life example

"The door is open" is either true or false. The program checks this.

School example

"The student passed the exam" is either true or false. The school's computer checks this to decide the next class.

Home example

"There is milk in the fridge" is either true or false. Your mother checks this before making tea.

Nigerian example

"The bank has enough money" is either true or false. The ATM checks this before giving cash.

Illustration

    TRUE AND FALSE
    ==============

    True:   [ YES ]  [ ON ]   [ Correct ]
    False:  [ NO ]   [ OFF ]  [ Wrong ]

    Every decision checks something: true or false?
        

Mini summary

True and false are the two answers to a yes-or-no question. They are the foundation of every decision.


Lesson 3 โ€” Comparisons

Definition

A comparison checks the relationship between two values. It asks questions like: Are they equal? Is one greater? Is one smaller?

Why it is important

Comparisons give us true or false answers. They are used in every decision.

Simple explanation

Think of weighing two bags of rice. You check: Which one is heavier? That is a comparison.

Common Comparisons

  • Equal to โ€” Is 5 equal to 5? Yes.
  • Not equal to โ€” Is 5 not equal to 3? Yes.
  • Greater than โ€” Is 10 greater than 5? Yes.
  • Less than โ€” Is 3 less than 7? Yes.
  • Greater than or equal to โ€” Is 5 โ‰ฅ 5? Yes.
  • Less than or equal to โ€” Is 3 โ‰ค 3? Yes.

Real-life example

A shop checks: Is the customer's money greater than or equal to the price? If yes, sell. If no, refuse.

School example

A teacher checks: Is the student's score greater than or equal to 50? If yes, pass. If no, fail.

Home example

Your mother checks: Is the pot big enough for the rice? If yes, use it. If no, find a bigger pot.

Nigerian example

A fuel attendant checks: Is the customer's money enough for the litres requested? If yes, pump. If no, ask for less.

Illustration

    COMPARISONS
    ===========

    5 == 5   ->  True   (equal)
    5 != 3   ->  True   (not equal)
    10 > 5   ->  True   (greater)
    3 < 7    ->  True   (less)
    5 >= 5   ->  True   (greater or equal)
    3 <= 3   ->  True   (less or equal)
        

Mini summary

Comparisons check relationships between values. They give true or false answers used in decisions.


Lesson 4 โ€” If Statements

Definition

An if statement is a way to tell the program: "If this is true, do that."

Why it is important

If statements are the most common way to make decisions in programming.

Simple explanation

Think of a rule: "If you finish your homework, you can watch TV." The if statement checks the condition and acts.

Example in Pseudocode

    IF it is raining THEN
      take an umbrella
    END IF
        

Real-life example

An ATM: IF the PIN is correct, THEN give money.

School example

IF a student's score is 50 or more, THEN mark as passed.

Home example

IF there is no milk, THEN buy milk.

Nigerian example

IF it is a public holiday, THEN the bank will be closed.

Illustration

    IF STATEMENT
    ============

    [ Is the condition true? ]
       /                  \
     Yes                   No
      |                     |
      V                     V
    [ Do the action ]    [ Skip the action ]

    Example: IF it is raining, THEN take umbrella.
        

Mini summary

An if statement tells the program: "If this is true, do that." It is the most common way to make decisions.


Lesson 5 โ€” Else Statements

Definition

An else statement tells the program what to do if the if condition is false.

Why it is important

Without else, the program would do nothing when the condition is false. Else gives the program a second option.

Simple explanation

Think of a rule: "If you finish your homework, you can watch TV. Else, you must study." The else gives the second option.

Example in Pseudocode

    IF it is raining THEN
      take an umbrella
    ELSE
      wear a hat
    END IF
        

Real-life example

An ATM: IF the PIN is correct, THEN give money. ELSE, show an error.

School example

IF a student's score is 50 or more, THEN mark as passed. ELSE, mark as failed.

Home example

IF there is no milk, THEN buy milk. ELSE, make tea.

Nigerian example

IF the fuel queue is short, THEN join it. ELSE, come back later.

Illustration

    IF-ELSE STATEMENT
    =================

    [ Is the condition true? ]
       /                  \
     Yes                   No
      |                     |
      V                     V
    [ Do action A ]      [ Do action B ]

    Example: IF it is raining, THEN take umbrella.
             ELSE, wear a hat.
        

Mini summary

An else statement tells the program what to do when the if condition is false. It gives a second option.


Lesson 6 โ€” Else If Statements

Definition

An else if statement lets the program check more than one condition. It is used when there are more than two options.

Why it is important

Many real-world decisions have more than two options. Else if handles these.

Simple explanation

Think of grading: If score is 70 or more, grade A. Else if 60 or more, grade B. Else if 50 or more, grade C. Else, fail.

Example in Pseudocode

    IF score >= 70 THEN
      grade = A
    ELSE IF score >= 60 THEN
      grade = B
    ELSE IF score >= 50 THEN
      grade = C
    ELSE
      grade = F
    END IF
        

Real-life example

A traffic light: IF green, go. ELSE IF yellow, slow down. ELSE (red), stop.

School example

A school grading system: IF 70+, A. ELSE IF 60+, B. ELSE IF 50+, C. ELSE, F.

Home example

IF there is rice, cook rice. ELSE IF there is beans, cook beans. ELSE, buy food.

Nigerian example

IF the queue is short, join. ELSE IF the queue is medium, wait. ELSE, come back later.

Illustration

    ELSE IF CHAIN
    =============

    [ Score >= 70? ]
       /          \
     Yes           No
      |             |
      V             V
    [ Grade A ]  [ Score >= 60? ]
                    /         \
                  Yes          No
                   |            |
                   V            V
                [ Grade B ] [ Score >= 50? ]
                              /         \
                            Yes          No
                             |            |
                             V            V
                          [ Grade C ] [ Grade F ]
        

Mini summary

Else if lets the program check more than one condition. It is used when there are more than two options.


Lesson 7 โ€” What is a Loop?

Definition

A loop is a way to repeat a set of steps many times. It saves you from writing the same steps again and again.

Why it is important

Without loops, programs would be very long. Loops make programs shorter and smarter.

Simple explanation

Think of brushing your teeth. You do not brush just once. You brush each tooth one by one. That is a loop.

Real-life example

A washing machine repeats the wash, rinse, and spin cycle. That is a loop.

School example

A teacher marks 30 exam papers one by one. That is a loop.

Home example

Your mother washes 10 plates one by one. That is a loop.

Nigerian example

A trader sells 50 bags of rice to different customers one by one. That is a loop.

Illustration

    LOOP CONCEPT
    ============

    [ Start ]
        |
        V
    [ Do the task ]
        |
        V
    [ More to do? ]
       /        \
     Yes         No
      |           |
      +--> repeat |
                  V
                [ End ]
        

Mini summary

A loop repeats a set of steps. It saves time and makes programs shorter.


Lesson 8 โ€” Repeat Loops

Definition

A repeat loop repeats a set of steps a fixed number of times. You tell the program how many times to repeat.

Why it is important

Repeat loops are simple and useful. You use them when you know exactly how many times to repeat.

Simple explanation

Think of doing 10 push-ups. You know the number. So you repeat 10 times.

Example in Pseudocode

    REPEAT 5 TIMES
      clap your hands
    END REPEAT
        

Real-life example

A music player repeats a song 3 times. You set the number.

School example

A teacher asks students to write a sentence 10 times. That is a repeat loop.

Home example

Your mother stirs the pot 20 times. That is a repeat loop.

Nigerian example

A football player does 50 sit-ups. That is a repeat loop.

Illustration

    REPEAT LOOP
    ===========

    [ Set count = 1 ]
          |
          V
    [ Do the task ]
          |
          V
    [ count = count + 1 ]
          |
          V
    [ Is count > 5? ]
       /          \
     No            Yes
      |              |
      +--> repeat    V
                   [ End ]

    Example: Clap 5 times.
        

Mini summary

A repeat loop repeats steps a fixed number of times. You tell the program how many times.


Lesson 9 โ€” While Loops

Definition

A while loop repeats a set of steps as long as a condition is true. It stops when the condition becomes false.

Why it is important

While loops are used when you do not know exactly how many times to repeat. You repeat until something changes.

Simple explanation

Think of waiting for a bus. While the bus has not arrived, you keep waiting. When it arrives, you stop waiting.

Example in Pseudocode

    WHILE there is water in the bucket
      scoop water
    END WHILE
        

Real-life example

A phone charges. While the battery is not full, keep charging.

School example

While there are exam papers, keep marking.

Home example

While there are dirty plates, keep washing.

Nigerian example

While there is fuel in the tank, keep selling.

Illustration

    WHILE LOOP
    ==========

    [ Check condition ]
          |
          V
    [ Is it true? ]
       /        \
     Yes         No
      |           |
      V           V
    [ Do task ]  [ End ]
      |
      +--> check condition again

    Example: WHILE water remains, scoop water.
        

Mini summary

A while loop repeats as long as a condition is true. It stops when the condition becomes false.


Lesson 10 โ€” For Loops

Definition

A for loop repeats steps a specific number of times, like a repeat loop. But it is more powerful. It can count and use the count.

Why it is important

For loops are used for counting, listing, and going through items one by one.

Simple explanation

Think of counting from 1 to 10. You say 1, 2, 3, and so on. A for loop does that.

Example in Pseudocode

    FOR number FROM 1 TO 10
      print number
    END FOR
        

Real-life example

A teacher calls roll numbers 1 to 30. That is a for loop.

School example

A student reads pages 1 to 20 of a book. That is a for loop.

Home example

Your mother counts 12 eggs in a tray. That is a for loop.

Nigerian example

A bus conductor counts 14 passengers. That is a for loop.

Illustration

    FOR LOOP
    ========

    FOR count FROM 1 TO 5
      print "Hello"
    NEXT count

    This prints "Hello" 5 times.

    Count:   1    2    3    4    5
           Hello Hello Hello Hello Hello
        

Mini summary

A for loop repeats steps a specific number of times. It is used for counting and listing.


Lesson 11 โ€” When to Use Decisions and Loops

Definition

Decisions are used when the program must choose. Loops are used when the program must repeat. Knowing when to use each is a key skill.

Why it is important

Using the wrong one makes programs confusing. Choosing the right one makes programs simple and clear.

Simple explanation

Think of a traffic light. It chooses between green, yellow, and red (decision). It also repeats the cycle (loop).

When to Use

Use a Decision When... Use a Loop When...
There are options There is repetition
The program must choose The program must repeat
Example: If it rains Example: For each student

Real-life example

A shop uses a decision: If a customer has money, sell. It uses a loop: For each item in the cart, calculate the price.

School example

A teacher uses a decision: If the score is above 50, pass. She uses a loop: For each student, mark the paper.

Home example

Your mother uses a decision: If there is no milk, buy more. She uses a loop: For each plate, wash it.

Nigerian example

A fuel attendant uses a decision: If the tank is empty, stop selling. He uses a loop: For each customer, pump fuel.

Illustration

    DECISION vs LOOP
    ================

    Decision:                  Loop:
    [ Choose A or B ]          [ Repeat this task ]
        |                          |
        V                          V
    One action                 Many actions

    Sometimes you need both!
        

Mini summary

Use decisions when the program must choose. Use loops when the program must repeat. Often you need both.


Lesson 12 โ€” Combining Decisions and Loops

Definition

Many programs use decisions inside loops. This means each time the loop runs, the program makes a decision.

Why it is important

Combining decisions and loops lets you handle complex tasks. It is the way real programs work.

Simple explanation

Think of a teacher marking exam papers. For each paper (loop), she checks if the score is above 50 (decision).

Example in Pseudocode

    FOR each student in the class
      IF student score >= 50 THEN
        mark student as passed
      ELSE
        mark student as failed
      END IF
    END FOR
        

Real-life example

A bank goes through each transaction (loop). If the amount is over โ‚ฆ1,000,000, it flags the transaction for review (decision).

School example

A school goes through each student (loop). If the fees are paid, the student can sit for exams (decision).

Home example

Your mother goes through each item in the fridge (loop). If it is expired, she throws it away (decision).

Nigerian example

A bus conductor goes through each passenger (loop). If the passenger has paid, he gives a ticket (decision).

Illustration

    DECISION INSIDE A LOOP
    ======================

    FOR each item
        |
        V
    [ Check condition ]
       /          \
     Yes           No
      |             |
      V             V
    [ Action A ] [ Action B ]
      |             |
      +------+------+
             |
             V
    [ Next item ]
        

Mini summary

Many programs use decisions inside loops. Each time the loop runs, the program makes a decision.

Summary of Main Lessons

You have now learned the core ideas of Module 2: what decisions are, true and false, comparisons, if statements, else and else if, what loops are, repeat loops, while loops, for loops, when to use decisions and loops, and how to combine them.


5. Key Vocabulary

Word Simple Definition
Decision A choice between two or more options.
Condition Something that is either true or false.
True Yes, correct, or on.
False No, wrong, or off.
Boolean A value that is either true or false.
Comparison Checking the relationship between two values.
If statement Do something if a condition is true.
Else statement Do something if the condition is false.
Else if statement Check another condition if the first is false.
Loop Repeating a set of steps.
Repeat loop Repeat a fixed number of times.
While loop Repeat as long as a condition is true.
For loop Repeat a specific number of times, often counting.
Counter A number that keeps track of how many times something happens.
Infinite loop A loop that never stops.

Summary of Key Vocabulary

These words will help you understand decisions and loops. Use them often so they become easy.


6. Important Concepts

Concept 1 โ€” Decisions Make Programs Smart

Decisions let programs react to different situations. Without them, programs would always do the same thing.

Concept 2 โ€” True and False Are the Foundation

Every decision checks something that is either true or false.

Concept 3 โ€” Loops Save Time

Loops repeat steps. They make programs shorter and easier to write.

Concept 4 โ€” Choose the Right Loop

Use repeat loops when you know the count. Use while loops when you do not.

Concept 5 โ€” Combine Decisions and Loops

Real programs often use decisions inside loops. This lets them handle complex tasks.

Summary of Important Concepts

These five concepts are the heart of Module 2. Read them again before moving on.


7. Step-by-step Explanations

Step-by-step: How to Write an If-Else in Pseudocode

  1. Identify the condition. What are you checking?
  2. Write the IF line. IF condition THEN.
  3. Write the action. What to do if true.
  4. Write the ELSE line. What to do if false.
  5. End with END IF. Close the decision.
  6. Test it. Try different conditions.
    WRITING AN IF-ELSE
    ==================

    IF score >= 50 THEN
      print "Passed"
    ELSE
      print "Failed"
    END IF
    

Step-by-step: How to Write a While Loop in Pseudocode

  1. Identify the condition. What must be true to keep looping?
  2. Write the WHILE line. WHILE condition.
  3. Write the actions. What to do inside the loop.
  4. Make sure something changes. Otherwise it will loop forever.
  5. End with END WHILE. Close the loop.
  6. Test it. Check if it stops at the right time.
    WRITING A WHILE LOOP
    ====================

    count = 1
    WHILE count <= 5
      print count
      count = count + 1
    END WHILE
    

Step-by-step: How to Draw a Decision Flowchart

  1. Start with an oval. Write "Start".
  2. Add a rectangle for the first step.
  3. Add a diamond for the decision.
  4. Label the arrows "Yes" and "No".
  5. Add rectangles for actions after each arrow.
  6. End with an oval. Write "End".
    DECISION FLOWCHART
    ==================

    ( Start )
        |
        V
    [ Read score ]
        |
        V
    < Score >= 50? >
      /          \
    Yes           No
     |             |
     V             V
    [ Print ]   [ Print ]
    [ Passed ]  [ Failed ]
     |             |
     +------+------+
            |
            V
         ( End )
    

Summary of Step-by-step Explanations

Writing decisions and loops, and drawing flowcharts, all follow clear steps. Following steps makes it easy.


8. Real-life Examples

Example 1 โ€” Traffic Light

A traffic light uses decisions: If green, go. Else if yellow, slow down. Else, stop. It also loops through the colours repeatedly.

Example 2 โ€” ATM

An ATM uses decisions: If PIN is correct, allow. Else, reject. It also loops: For each transaction, process it.

Example 3 โ€” Washing Machine

A washing machine uses a loop: While there is water, keep washing. If the timer ends, stop.

Example 4 โ€” Online Shopping Cart

An online cart uses a loop: For each item, add the price. It uses a decision: If the total is over โ‚ฆ50,000, give free delivery.

Example 5 โ€” Music Player

A music player uses a loop: For each song in the playlist, play it. If the user presses stop, stop.

Summary of Real-life Examples

Decisions and loops appear in traffic lights, ATMs, washing machines, shopping carts, and music players.


9. Nigerian Examples

Example 1 โ€” Buying Airtime

Decision: If you entered the right PIN, airtime is added. Else, an error message appears.

Example 2 โ€” Bank Transfer

Decision: If your balance is enough, the transfer goes through. Else, the transfer fails.

Example 3 โ€” POS Payment

Loop: For each item, add the price. Decision: If the total is correct, confirm payment.

Example 4 โ€” Fuel Station

Loop: For each customer, pump fuel. Decision: If the tank is empty, stop selling.

Example 5 โ€” School Result Portal

Loop: For each subject, check the score. Decision: If the score is 50 or more, mark as pass.

Summary of Nigerian Examples

Nigeria has many examples of decisions and loops: airtime, bank transfers, POS, fuel stations, and school portals.


10. Fun Examples Children Can Relate To

Example 1 โ€” Video Games

Decision: If the player touches an enemy, lose a life. Loop: For each level, load the level.

Example 2 โ€” Choosing Clothes

Decision: If it is cold, wear a jacket. Else, wear a T-shirt.

Example 3 โ€” Playing Hide and Seek

Loop: Count to 20. Decision: If you find everyone, the game ends.

Example 4 โ€” Making a Sandwich

Decision: If you have cheese, add cheese. Else, skip it. Loop: For each slice, add filling.

Example 5 โ€” Sharing Sweets

Loop: For each friend, give one sweet. Decision: If there are no sweets left, stop.

Summary of Fun Examples

Decisions and loops appear in video games, choosing clothes, hide and seek, sandwiches, and sharing sweets.


11. Everyday Examples

Task Decision Loop
Brushing teeth If tooth is clean, move on For each tooth
Charging phone If charged, unplug While not full, keep charging
Cooking rice If soft, serve While cooking, stir
Going to school If raining, take umbrella For each subject, attend class
Sending a text If recipient exists, send For each message, send

Summary of Everyday Examples

Even simple daily activities use decisions and loops. Now you can see them everywhere.


12. Parent Tips

  1. Point out decisions in daily life. "If it rains, we take an umbrella."
  2. Point out loops. "We wash each plate one by one."
  3. Ask your child to spot decisions. In a game, in a movie, in a chore.
  4. Play decision games. "If I say red, jump. If I say blue, sit."
  5. Play loop games. "Clap 5 times. Now clap until I say stop."
  6. Practise pseudocode. Ask your child to write "IF... ELSE" for a daily rule.
  7. Praise clear thinking. When your child explains a decision, praise them.
  8. Be patient. Logical thinking takes practice.

Summary of Parent Tips

Parents can help children learn decisions and loops through daily activities and simple games.


13. Interesting Facts

  1. The if statement is one of the oldest ideas in programming.
  2. Loops can repeat millions of times in a second.
  3. Without loops, some programs would be millions of lines long.
  4. Infinite loops are one of the most common programming mistakes.
  5. Traffic lights use loops and decisions together.
  6. Some computer games use thousands of loops every second.
  7. The concept of true and false is called Boolean logic, named after a mathematician called George Boole.
  8. In Nigeria, many tech companies teach if-statements and loops in their first coding lessons.

Summary of Interesting Facts

Decisions and loops are powerful, old, and used everywhere.


14. Did You Know?

  • Did you know that every decision in a program uses true or false?
  • Did you know that a single loop can save hundreds of lines of code?
  • Did you know that the first computers had no loops, and programmers had to write every step by hand?
  • Did you know that traffic lights, elevators, and washing machines all use decisions and loops?
  • Did you know that an infinite loop can freeze a whole program?
  • Did you know that "else if" is sometimes called "elif" in some programming languages?

Summary of Did You Know?

Decisions and loops are full of surprises. The more you learn, the more interesting they become.


15. Remember This

  • A decision is a choice between options.
  • Every decision uses true or false.
  • Comparisons check relationships between values.
  • An if statement runs when a condition is true.
  • An else statement runs when a condition is false.
  • An else if statement checks another condition.
  • A loop repeats a set of steps.
  • Repeat loops repeat a fixed number of times.
  • While loops repeat as long as a condition is true.
  • For loops repeat a specific number of times, often counting.

Summary of Remember This

These ten points are the heart of Module 2. Read them again before moving on.


16. Common Mistakes

  1. Forgetting the else. Without else, the program does nothing when the condition is false.
  2. Using the wrong comparison. Using "greater than" when you mean "greater than or equal to".
  3. Writing an infinite loop. A loop that never stops.
  4. Not changing the condition inside a while loop. This creates an infinite loop.
  5. Using a loop when a decision is needed. They are different.
  6. Forgetting to close loops or if statements. Use END IF and END LOOP.
  7. Making conditions too complex. Keep them simple.
  8. Giving up too soon. Logic takes practice.

Summary of Common Mistakes

Avoiding these mistakes will make you a better logical thinker than many adults.


17. Best Practices

  1. Keep conditions simple and clear.
  2. Always include an else when there is another option.
  3. Use else if for multiple options.
  4. Make sure loops change something, so they stop.
  5. Choose the right loop for the task.
  6. Test your code with different values.
  7. Draw flowcharts for decisions and loops.
  8. Write pseudocode before real code.
  9. Look for loops and decisions in daily life.
  10. Practice every day.

Summary of Best Practices

These ten practices will help you write better decisions and loops.


18. ASCII Illustrations, Diagrams, Flowcharts, and Timelines

Diagram 1 โ€” A Simple Decision

    A SIMPLE DECISION
    =================

    [ Is it raining? ]
       /           \
     Yes            No
      |              |
      V              V
    [ Take        [ Do not
      umbrella ]    take umbrella ]
    

Diagram 2 โ€” True and False

    TRUE AND FALSE
    ==============

    True:   [ YES ]  [ ON ]   [ Correct ]
    False:  [ NO ]   [ OFF ]  [ Wrong ]
    

Diagram 3 โ€” If-Else Statement

    IF-ELSE STATEMENT
    =================

    [ Is the condition true? ]
       /                  \
     Yes                   No
      |                     |
      V                     V
    [ Do action A ]      [ Do action B ]
    

Diagram 4 โ€” Else If Chain

    ELSE IF CHAIN
    =============

    [ Score >= 70? ]
       /          \
     Yes           No
      |             |
      V             V
    [ Grade A ]  [ Score >= 60? ]
                    /         \
                  Yes          No
                   |            |
                   V            V
                [ Grade B ] [ Score >= 50? ]
                              /         \
                            Yes          No
                             |            |
                             V            V
                          [ Grade C ] [ Grade F ]
    

Diagram 5 โ€” While Loop

    WHILE LOOP
    ==========

    [ Check condition ]
          |
          V
    [ Is it true? ]
       /        \
     Yes         No
      |           |
      V           V
    [ Do task ]  [ End ]
      |
      +--> check condition again
    

Diagram 6 โ€” Decision Inside a Loop

    DECISION INSIDE A LOOP
    ======================

    FOR each item
        |
        V
    [ Check condition ]
       /          \
     Yes           No
      |             |
      V             V
    [ Action A ] [ Action B ]
      |             |
      +------+------+
             |
             V
    [ Next item ]
    

Summary of Illustrations

These diagrams help you see decisions and loops clearly. Draw them yourself to remember them better.


19. Comparison Tables

Table 1 โ€” If vs Else If vs Else

If Else If Else
Checks the first condition Checks another condition Runs when all conditions are false
Runs if true Runs if the first was false but this one is true Runs always as the last option
One per decision Can have many One per decision

Table 2 โ€” Repeat vs While vs For

Repeat Loop While Loop For Loop
Fixed number of times Until a condition is false Fixed number, with counting
You know the count You do not know the count You know the range
Example: Clap 5 times Example: While water remains Example: Count from 1 to 10

Table 3 โ€” Decision vs Loop

Decision Loop
Chooses between options Repeats steps
Uses true or false Uses a condition too
Runs once per check Runs many times
Example: If it rains Example: For each student

Summary of Comparison Tables

Comparing ideas side by side helps you remember the differences clearly.


20. Summary After Every Lesson (Consolidated)

Lesson Main Idea
Lesson 1 A decision is a choice between options.
Lesson 2 True and false are the two answers to a yes-or-no question.
Lesson 3 Comparisons check relationships between values.
Lesson 4 An if statement runs when a condition is true.
Lesson 5 An else statement runs when a condition is false.
Lesson 6 An else if statement checks another condition.
Lesson 7 A loop repeats a set of steps.
Lesson 8 Repeat loops repeat a fixed number of times.
Lesson 9 While loops repeat as long as a condition is true.
Lesson 10 For loops repeat a specific number of times, often counting.
Lesson 11 Use decisions to choose, and loops to repeat.
Lesson 12 Real programs combine decisions and loops.

21. End-of-Module Summary

Congratulations! You have completed Module 2. Let us review what you have learned.

You began by learning that a decision is a choice between options. Programs use decisions to react to different situations.

You learned about true and false, the two answers to a yes-or-no question. Every decision checks something that is either true or false.

You explored comparisons โ€” equal, not equal, greater than, less than, and more.

You learned how to write if statements โ€” "If this is true, do that."

You added else and else if to handle more options.

You discovered loops โ€” ways to repeat steps. You learned about repeat loops, while loops, and for loops.

You learned when to use decisions and when to use loops. You also learned how to combine them.

    MODULE 2 SUMMARY MAP
    ====================

    [ Decision ] --> [ True / False ] --> [ Comparisons ]
              |
              V
    [ If ] --> [ Else ] --> [ Else If ]
              |
              V
    [ Loop ] --> [ Repeat ] --> [ While ] --> [ For ]
              |
              V
    [ Decision + Loop Together! ]
    

Well done! You now understand how programs make decisions and repeat tasks. In Module 3, you will learn how programs store and use information.


22. Frequently Asked Questions (10 Questions)

Question 1: What is a decision in programming?

A decision is a choice between two or more options. Programs use decisions to react to different situations.

Question 2: What is true and false?

True and false are the two answers to a yes-or-no question. They are the foundation of every decision.

Question 3: What is a comparison?

A comparison checks the relationship between two values. It asks: Are they equal? Is one greater? Is one smaller?

Question 4: What is an if statement?

An if statement tells the program: "If this is true, do that."

Question 5: What is an else statement?

An else statement tells the program what to do when the if condition is false.

Question 6: What is an else if statement?

An else if statement lets the program check more than one condition. It is used when there are more than two options.

Question 7: What is a loop?

A loop is a way to repeat a set of steps many times.

Question 8: What is the difference between a repeat loop and a while loop?

A repeat loop repeats a fixed number of times. A while loop repeats as long as a condition is true.

Question 9: What is an infinite loop?

An infinite loop is a loop that never stops. It happens when the condition never becomes false.

Question 10: Can I use decisions and loops in daily life?

Yes! You already use them for cooking, dressing, playing games, and many other tasks.


23. Matching Exercises

Exercise 1 โ€” Match the Word to the Meaning

Column A (Word) Column B (Meaning)
1. Decision A. Repeat a fixed number of times
2. If statement B. A choice between options
3. Loop C. Run when a condition is true
4. Repeat loop D. Run when a condition is false
5. Else statement E. Repeat a set of steps

Answers: 1-B, 2-C, 3-E, 4-A, 5-D

Exercise 2 โ€” Match the Task to Its Type

Column A (Task) Column B (Type)
1. If it rains, take umbrella A. While loop
2. For each student, mark paper B. For loop
3. While water remains, scoop C. If statement
4. Clap 5 times D. Repeat loop

Answers: 1-C, 2-B, 3-A, 4-D

Summary of Matching Exercises

Matching helps you connect words to meanings quickly.


24. Scenario-based Exercises

Scenario 1 โ€” The Silent ATM

A customer enters the wrong PIN at an ATM. The ATM does nothing. No message appears. The customer is confused.

Questions:

  1. What is missing in the program?
  2. What should the ATM do?
  3. Write pseudocode for the correct behaviour.

Scenario 2 โ€” The Endless Song

A music player keeps playing the same song forever. The user cannot stop it.

Questions:

  1. What kind of mistake is this?
  2. How could the programmer fix it?
  3. What is the name of this mistake?

Scenario 3 โ€” The Missed Decision

A shopping website always gives free delivery, even when the order is small. The company is losing money.

Questions:

  1. What decision is missing?
  2. How should the program check?
  3. Write pseudocode for the correct decision.

Summary of Scenario-based Exercises

These scenarios help you apply what you have learned to real situations.


25. Group Activity

Activity: Design a Decision Flowchart for a Game

Group size: 3โ€“5 students

Time: 40 minutes

Materials: Paper, pencil, ruler

Instructions:

  1. Choose a simple game (e.g., guess the number, rock-paper-scissors).
  2. Write the rules as decisions (if, else).
  3. Include at least one loop (repeat until the game ends).
  4. Draw a flowchart using ovals, rectangles, and diamonds.
  5. Present your flowchart to the class.

Goal: To practise decisions and loops together.


26. Individual Activity

Activity: My Day in Decisions and Loops

Time: 20 minutes

Materials: Notebook, pencil

Instructions:

  1. Write three decisions you made today (using if/else).
  2. Write three loops you did today (like brushing each tooth).
  3. Draw a simple flowchart for one decision.
  4. Draw a simple flowchart for one loop.

Goal: To connect decisions and loops to your own daily life.


27. Mini Project

Project: Design a Simple Quiz Program on Paper

Time: 1โ€“2 hours

Materials: Paper, pencil, ruler

Instructions:

  1. Choose 5 simple questions (e.g., maths or general knowledge).
  2. Write pseudocode that asks each question in a loop.
  3. Inside the loop, use a decision: If the answer is correct, add 1 to the score.
  4. After the loop, use a decision: If the score is 3 or more, say "Well done". Else, say "Try again".
  5. Draw a flowchart of your program.
  6. Present your project to the class.

Goal: To practise decisions and loops together.


28. Practical Assignment

Assignment: Observe Decisions and Loops in Real Life

Time: 1 week

Materials: Notebook, pencil

Instructions:

  1. For one week, look for decisions and loops in daily life.
  2. Write down at least 5 examples of each.
  3. For one decision, write pseudocode using if/else.
  4. For one loop, write pseudocode using while or for.
  5. Write a short report on what you learned.

Goal: To see how decisions and loops appear in real life.


29. Key Takeaways

  1. A decision is a choice between options.
  2. Every decision uses true or false.
  3. Comparisons check relationships between values.
  4. If statements run when a condition is true.
  5. Else statements run when a condition is false.
  6. Else if statements check another condition.
  7. Loops repeat a set of steps.
  8. Repeat loops repeat a fixed number of times.
  9. While loops repeat as long as a condition is true.
  10. For loops repeat a specific number of times, often counting.

30. Classroom Discussion Questions

  1. Why do programs need decisions?
  2. What would happen if a program had no loops?
  3. Can you give an example of a decision you made today?
  4. Can you give an example of a loop you used today?
  5. What is the difference between if and else?
  6. When would you use else if?
  7. What is the difference between a while loop and a for loop?
  8. What happens if a loop never stops?
  9. Why is it useful to combine decisions and loops?
  10. What did you enjoy most in this module?

31. Preparation for the Next Module

You have finished Module 2. Well done! Here is how to prepare for Module 3, which is all about Storing and Using Information.

  1. Review your key words. Make sure you can explain decision, if, else, loop, and while loop in your own words.
  2. Practise writing pseudocode. Write if/else and loops for daily tasks.
  3. Draw flowcharts. Use ovals, rectangles, diamonds, and arrows.
  4. Look for information in daily life. Notice how you store and use information (names, numbers, lists).
  5. Bring your curiosity. Module 3 will teach you about variables, data types, lists, and functions.
    TRANSITION TO MODULE 3
    ======================

    [ Module 2: Making Decisions and Repeating Tasks ]
              |
              V
    [ Module 3: Storing and Using Information ]
              |
              V
    [ You will learn: variables, data types,
      lists, functions, and input/output ]
    

See you in Module 3. Keep thinking like a programmer!


๐Ÿ† Get Certified

๐Ÿ”’

Earn this certificate

Every lesson is already free to read. Sign up, finish the lessons, pass the exam (โ‚ฆ2,000 or 20,000 coins), and get a verified certificate with your name on it.

๐ŸŽ“ Sign Up to Get Certified
๐Ÿ› ๏ธ Practice Tools
Hands-on simulators & labs - subscription required.
โ†’
๐ŸŽฏ Internship Tasks
Real-world tasks to build your portfolio - unlock them with a subscription.
โ†’