Welcome to the World of Programming!

Ever wondered how your favorite apps "think"? It’s not magic—it’s all about Constructs. Think of constructs as the building blocks of code. Just like a recipe has steps, ingredients, and decisions (like "bake for 20 minutes OR until golden"), programs use these same logical structures to solve problems.

In this chapter, we will learn how to identify these building blocks and use them to write your own amazing programs. Don't worry if it seems like a lot at first; once you see the patterns, it becomes as natural as following a map!

1. The Ingredients: Variables and Constants

Before we can do anything, we need to store data. We use two main types of containers:

Variables: These are containers where the value can change while the program is running. Imagine a "Score" box in a video game; it starts at 0 and goes up.
Constants: These are containers where the value stays the same. Think of the value of \( \pi \) (Pi) or the "Gravity" setting in a game. We use constants to make code easier to read and to prevent accidental changes.

Initialisation and Assignment

Initialisation: This is the very first time you give a variable a value. It’s like buying a new folder and putting the first piece of paper inside.
Assignment: This is when you set (or change) the value of a variable. In many languages, we use the \( = \) sign for this. For example: \( Score = Score + 10 \).

Quick Review:
Variable: Can change (e.g., player speed).
Constant: Stays the same (e.g., maximum lives).
Assignment: Giving a value to a container.

2. The Order: Command Sequences

A Sequence is the most basic construct. It simply means that the computer carries out instructions one after another, from top to bottom. Order matters!

Analogy: Think of your morning routine. If you put your shoes on before your socks, you’re going to have a bad time! Programming is the same.

3. Making Decisions: Selection

Sometimes a program needs to choose between different paths. We call this Selection. This usually involves an IF statement.

Real-world example:
IF it is raining, THEN take an umbrella. ELSE, wear sunglasses.

In programming, we use relational operators to make these decisions:
• \( == \) (Equal to)
• \( != \) (Not equal to)
• \( > \) (Greater than)
• \( < \) (Less than)

Common Mistake: Many students use a single \( = \) when they mean "is it equal to?". Remember: \( = \) is for assigning a value, while \( == \) is for comparing two values!

4. Doing it Again: Repetition and Iteration

Computers are great at doing boring tasks over and over again without getting tired. We use Loops for this. There are three main types you need to know:

Count-Controlled Loops (Repetition)

Use this when you know exactly how many times you want to repeat something.
Example: "Clap your hands 5 times."
In code, this is often a FOR loop.

Condition-Controlled Loops (Repetition)

Use this when you want to keep going until something changes. You might not know how long it will take.
Example: "Keep running until you reach the finish line."
In code, this is often a WHILE loop.

Iteration over a Data Structure

This is a special kind of loop that looks at every single item in a collection (like a list or an array).
Example: "Check every student's name on the register."

Did you know? Using loops makes your code much shorter. Instead of writing "Print 'Hello'" 100 times, you can just write it once inside a loop!

5. Talking to the Computer: Input and Output

Programs aren't very useful if they can't talk to us!
Input: Data the user gives to the program (like typing your username).
Output: Information the program shows to the user (like printing "Game Over" on the screen).

6. The Helpers: Subprograms and Parameters

As programs get bigger, they get messy. We use Subprograms (also called functions or procedures) to group code into reusable chunks.

Analogy: Imagine you have a "Minion" who knows exactly how to make a sandwich. Instead of explaining every step (get bread, add butter, add jam) every time you're hungry, you just shout "Make Sandwich!".

Parameters: These are the specific "options" you give to a subprogram. For the sandwich subprogram, the parameter might be the type of jam. "Make Sandwich (Strawberry)" vs "Make Sandwich (Raspberry)".

7. Writing Good Code: The Golden Rule

When you write code blocks or subprograms, you should aim for single entry and exit points. This means the code should start at the top and finish at the bottom. Avoid "jumping" out of the middle of a loop or subprogram if you can help it—it makes your code much easier to debug (fix)!

Key Takeaways for the Exam:
1. Sequence: Instructions in order.
2. Selection: IF statements (making choices).
3. Repetition: FOR loops (count-controlled) and WHILE loops (condition-controlled).
4. Variables change; Constants don't.
5. Subprograms make code reusable and easier to manage.

Don't worry if this seems tricky at first! The best way to learn these constructs is to try writing them. Start small, and soon you'll be building complex programs one block at a time.