Menu
Theme

Form 3
Course Content
View Overview

Key Concepts

Programming

Habari Mwanafunzi! Let's Uncover the Secrets of Programming!

Welcome to the exciting world of programming! You probably use apps like M-Pesa, WhatsApp, or even play games on your phone. Have you ever wondered how they work? It’s not magic, it’s programming! Think of a computer as a very obedient but very simple-minded shamba boy. It will do exactly what you tell it to, but you must give it very clear, step-by-step instructions. Today, we are going to learn the basic "language" to give these instructions. These are the key concepts, the building blocks for creating anything from a simple calculator to the next big Kenyan app. Sawa? Let's begin!

1. Variables and Data Types: The Storage Boxes

Imagine you have different items to store: sugar, water, and stones. You wouldn't store them all in the same container, would you? You'd use a sugar dish for sugar, a mtungi for water, and a bucket for stones. In programming, we have similar storage containers called variables. A variable is simply a named location in the computer's memory where we can store information.

But what kind of information? That's where Data Types come in. They tell the computer what kind of data we are storing in our variable "box". Here are the most common ones:

  • Integer: This is for whole numbers. Think about the number of students in your class or the price of a mandaazi. Example: 45, 10, -50.
  • Float (or Real): These are numbers with decimal points. Think about the height of Mount Kenya in kilometres or your average grade. Example: 5.2, 78.5, -19.1.
  • String: This is for text. Your name, your school's name, or the word "Nairobi" are all strings. We usually put them in quotation marks. Example: "Juma", "Kenya High School".
  • Boolean: This is the simplest one! It can only have two values: True or False. Think of it as a light switch, it's either ON (True) or OFF (False). Example: Is it raining? True. Are you the school principal? False.
Real-World Example: An M-Pesa Transaction

When you send money, M-Pesa has to store the details. It might use variables like this:


customerName = "Wanjiku"      // String
amountSent = 250.50          // Float
transactionFee = 15          // Integer
isCompleted = True           // Boolean
    

2. Control Structures: The Brain of the Program

Giving instructions is good, but what if we need our program to make decisions or repeat actions? That's where control structures come in. They control the flow of the program, just like a traffic police officer controls the flow of cars at a junction.

a) Sequence

This is the most basic structure. It means the instructions are followed one after another, in order, from top to bottom. Just like a recipe for ugali: you must boil the water before you add the flour. You can't do it the other way around!


    +-------------------------+
    |      Start Program      |
    +-------------------------+
                |
                V
    +-------------------------+
    |   Instruction 1 (e.g. Get number)   |
    +-------------------------+
                |
                V
    +-------------------------+
    | Instruction 2 (e.g. Calculate) |
    +-------------------------+
                |
                V
    +-------------------------+
    |  Instruction 3 (e.g. Display)   |
    +-------------------------+
                |
                V
    +-------------------------+
    |       End Program       |
    +-------------------------+

b) Selection (IF...ELSE...)

This is how a program makes decisions. It checks if a certain condition is true or false and then follows a different path based on the outcome.

Kenyan Example: Passing an Exam

Your teacher uses selection to decide if you passed. The condition is "Is the student's score 40 or more?".

IF score is greater than or equal to 40, THEN the result is 'Pass'.

ELSE (otherwise), the result is 'Fail'.


IF score >= 40 THEN
    PRINT "Congratulations, you have passed!"
ELSE
    PRINT "You need to work harder."
ENDIF
    

Image Suggestion: An illustration of a Kenyan student in school uniform standing at a fork in a path. One path is sunny and labeled "Score >= 40: PASS". The other path is cloudy and labeled "Score < 40: FAIL". The student is looking at their report form before choosing a path. The style should be a friendly, colourful cartoon.

c) Iteration (Loops)

Iteration means repeating an action multiple times. This is also called a loop. Imagine fetching water from a well to fill a big drum. You repeat the action of going, filling your bucket, walking back, and pouring it in, over and over, until the drum is full.

Kenyan Example: A Matatu Conductor

A conductor has to collect fare from every passenger. He doesn't have a separate instruction for each person. He just has one set of instructions that he loops through:

FOR EACH passenger in the matatu:

  1. Ask for fare.
  2. Receive money.
  3. Give change if necessary.

He repeats this until he has collected fare from everyone.


          +----------------------------+
          | Start: Any passengers left?| --(No)--> End
          +----------------------------+
                      |
                     (Yes)
                      |
                      V
          +----------------------------+
          |      Collect Fare          |
          |      Give Change           |
          +----------------------------+
                      |
                      +----(Go back and repeat)

3. Algorithm & Pseudocode: The Master Plan

Before a builder starts building a house, they need a blueprint, a plan. In programming, our plan is called an algorithm.

An algorithm is a finite, step-by-step list of instructions to solve a specific problem. It’s the logic, the recipe, written in plain English.

Pseudocode (which means "fake code") is a way of writing down our algorithm that is halfway between English and an actual programming language. It helps us plan the program's logic without worrying about the strict rules (syntax) of a language like Python or Java.

Example: The Plan to Calculate the Area of a Shamba (Rectangle)

The Algorithm (in English):

  1. Start.
  2. Ask the user for the length of the shamba.
  3. Ask the user for the width of the shamba.
  4. Calculate the area by multiplying the length by the width.
  5. Show the calculated area to the user.
  6. Stop.

The Pseudocode:


BEGIN
    DISPLAY "Enter the length of the shamba:"
    INPUT length

    DISPLAY "Enter the width of the shamba:"
    INPUT width

    area = length * width

    DISPLAY "The area of the shamba is: ", area
END
    

See? It's clear, easy to read, and anyone can understand the logic before we write a single line of real code!

Tafakari (Let's Reflect)

Hongera! You have just learned the absolute core concepts of programming. Everything you will ever create, from a simple website to a complex system, will use these ideas:

  • Variables: The boxes to store your data.
  • Control Structures (Sequence, Selection, Iteration): The brain that controls the program's flow.
  • Algorithms & Pseudocode: The plan you make before you start building.

Learning to code is like learning a new language or how to play an instrument. It takes practice. Don't be afraid to make mistakes – that's how we learn! For your next step, try writing a simple algorithm and pseudocode for a daily task, like "how to make a cup of tea" or "how to walk from your home to school". Keep practicing, and soon you'll be giving computers instructions like a pro!

Pro Tip

Take your own short notes while going through the topics.

Previous Key Concepts
KenyaEdu
Add KenyaEdu to Home Screen
For offline access and faster experience