Program Development: Bringing Your Ideas to Life!

Hey there! Welcome to the exciting world of Program Development. Ever wondered how your favourite mobile games, apps, or websites are made? It all starts here! In this chapter, we're going to learn the fundamental building blocks that programmers use to write instructions for a computer. Think of it as learning the grammar of a new language – the language of computers.

Don't worry if you've never coded before. We'll break everything down into simple, easy-to-understand steps. By the end, you'll understand how to think like a programmer and solve problems by creating your own simple programs. Let's get started!


1. The Building Blocks: Storing Information

Before a program can do anything cool, it needs a way to remember things. Just like you use your brain to remember a friend's birthday or a shopping list, programs use special containers to store information.

Variables: The Labelled Boxes

A variable is like a box with a label on it where you can store one piece of information. You can change what's inside the box whenever you want. The label (the variable's name) helps you find the right box later.

Example: We can create a variable called score and put the number 100 inside it.
score = 100
Later, the player might lose points, so we can change the value:
score = 90

Constants: The "Do Not Change" Boxes

A constant is just like a variable, but once you put something inside, you can't change it. It's like a box that's been sealed shut! This is useful for values that should never change in your program.

Example: The value of Pi is always the same. We can store it in a constant.
PI = 3.14159
Using a constant like PI makes your code easier to read and prevents you from accidentally changing an important value.

Lists (One-Dimensional Arrays): The Organized Collection

What if you need to store a whole list of items, like the scores of all students in a class? Using one variable for each would be a pain! Instead, we use a list (also known as a one-dimensional array).

Think of a list as an egg carton or a pill organiser – a single container with many numbered compartments. Each compartment can hold one item, and you can access it using its position number, called an index.

Example: A list of high scores.
highScores = [550, 521, 498, 450]
To get the very first score, we use its index. (Note: In many programming languages, the first index is 0!)
OUTPUT highScores[0] (This would show 550)

Key Takeaway

Variables store information that can change.
Constants store information that never changes.
Lists (Arrays) store a collection of related items in an ordered sequence.


2. Making Things Happen: Statements and Operators

Now that we know how to store information, let's learn how to work with it. We do this using statements and operators.

Assignment Statements: Giving a Variable its Value

We've already seen this! An assignment statement uses the equals sign (=) to put a value into a variable.

age = 17
The most important thing to remember is that = here means "assign the value on the right to the variable on the left". It does not mean they are mathematically equal.

Common Mistake Alert! Don't confuse the assignment operator (=) with the relational operator for "is equal to?" (which is often ==). They do very different jobs!

Input and Output Statements

Programs need to communicate with the user.

  • Input: An input statement gets data from the user and stores it in a variable. It's like the program is asking a question.

    Example: INPUT userName (The program waits for the user to type their name).
  • Output: An output statement displays information on the screen. It's like the program is talking.

    Example: OUTPUT "Hello, " + userName (If the user typed "Mary", this would show "Hello, Mary").
Operators: The Tools for Doing Work

Operators are special symbols that perform calculations or comparisons.

1. Arithmetic Operators: These are for maths!

  • + (Addition)

  • - (Subtraction)

  • * (Multiplication)

  • / (Division)

  • MOD (Modulus): This one is cool! It gives you the remainder of a division. For example, 10 MOD 3 is 1 (because 10 divided by 3 is 3 with a remainder of 1). Think of it like a 12-hour clock: 14 o'clock is 2 o'clock (14 MOD 12 = 2).

2. Relational Operators: These compare two values and give a True/False answer.

  • == (Is equal to?)

  • != (Is not equal to?)

  • > (Is greater than?)

  • < (Is less than?)

  • >= (Is greater than or equal to?)

  • <= (Is less than or equal to?)

Example: age > 17 would be True if the age variable holds 18, and False if it holds 16.

3. Boolean (Logical) Operators: These combine True/False values.

  • AND: True only if both sides are true. (You must have a ticket AND be on time to enter.)

  • OR: True if at least one side is true. (To pay, you can use a credit card OR cash.)

  • NOT: Flips the value. NOT True becomes False. (The door is NOT locked.)

Expressions

An expression is any combination of values, variables, and operators that a computer can evaluate to produce a single value.
Examples: 5 + 10 (evaluates to 15) or price * 1.1 or score > 50 AND level == 3.

Key Takeaway

We use assignment statements (=) to store values. We use input/output to talk to the user. We use operators (arithmetic, relational, Boolean) to process and compare data within expressions.


3. The Three Superpowers of Programming: Control Structures

A program is more than just a list of instructions. To solve real problems, we need to control the order in which instructions are executed. There are three main ways to control this flow.

Memory Aid: Remember the three superpowers with S.S.I. - Sequence, Selection, Iteration!

Sequence: The Default Path

This is the simplest control structure. Sequence means the computer executes your instructions one after another, from top to bottom, in the order you write them. It's like following a recipe step-by-step.

Selection: Making Choices (IF...THEN...ELSE)

Selection allows your program to make decisions. It checks if a condition is true or false and runs different blocks of code based on the outcome. Think of it as a fork in the road.

The most common selection statement is IF...THEN...ELSE.

Simple Example: Checking if a student passed.
IF score >= 50 THEN
    OUTPUT "Congratulations, you passed!"
ELSE
    OUTPUT "Better luck next time."
END IF

You can also chain them together to handle multiple conditions (this is called multi-way selection).

Iteration: Repeating Yourself (Loops)

Iteration means repeating a block of code multiple times. This is also called a loop. It's incredibly useful for saving time and avoiding repetitive code.

Important Note: For your syllabus, you only need to understand basic loops. Nested loops (a loop inside another loop) are not required.

There are two main types of loops:

  • For Loop: Use this when you know exactly how many times you want to repeat something.

    Example: Say "Hello" 3 times.
    FOR count FROM 1 to 3
        OUTPUT "Hello!"
    END FOR
  • While Loop: Use this when you want to repeat as long as a certain condition is true. You might not know how many repeats it will take.

    Example: Keep asking for a password until the correct one is entered.
    INPUT password
    WHILE password != "secret123"
        OUTPUT "Wrong password. Try again."
        INPUT password
    END WHILE
    OUTPUT "Access granted!"
Quick Review

Sequence: Do things in order.
Selection (IF): Make a choice.
Iteration (Loop): Repeat things.


4. Let's Solve a Problem: Finding the Average Score

Let's put everything together to solve a real problem from the syllabus: Find the average value in a list.

The Problem: We have a list of student scores: [80, 95, 72, 88, 91]. We need to write a program to calculate and display the average score.

Step 1: The Plan (The Algorithm)

Before we write any code, let's think about the steps in plain English. How would *you* calculate an average?

  1. First, you need to add up all the scores. We'll need a variable to keep track of the total sum, starting at 0.
  2. Then, you need to go through the list of scores, one by one.
  3. For each score, you add it to your running total.
  4. Once you've added all the scores, you need to know how many scores there were.
  5. Finally, you divide the total sum by the number of scores. That's the average!
  6. Display the result.
Step 2: The Code (in Pseudocode)

Now let's translate our plan into pseudocode, which is a simplified, code-like language.

// 1. Set up our variables
scores = [80, 95, 72, 88, 91] // This is our list
total = 0 // A variable to store the sum, starting at 0
numberOfScores = 5 // We have 5 scores
average = 0 // A variable for the final answer

// 2. Add up all the scores using a loop (Iteration)
FOR EACH score IN scores
    total = total + score // Add the current score to our total
END FOR

// 3. Calculate the average
average = total / numberOfScores

// 4. Display the result
OUTPUT "The average score is: " + average

This simple program uses a list, several variables, arithmetic operators (`+`, `/`), an assignment statement (`=`), an iteration (the `FOR` loop), and an output statement. You've just seen all the core concepts of program development in action!

Did you know? The first computer "bug" was a real insect! In 1947, engineers found a moth stuck in a relay of the Harvard Mark II computer, causing it to malfunction. They taped the moth to their logbook and wrote "First actual case of bug being found." The term has been used for program errors ever since!