Welcome to the World of Programming!

Hello there! Whether you are a coding pro or just starting your journey, this chapter is the "engine room" of Computer Science. Programming is all about giving a computer a set of instructions to solve a problem. It’s a bit like writing a recipe: if you follow the steps correctly, you get a delicious cake (or, in our case, a working app!).

Don’t worry if some of this seems like a lot at first. We’re going to break it down into small, bite-sized pieces so you can master the fundamentals of the AQA A Level Computer Science (7517) curriculum. Let’s get started!

1. The Building Blocks: Data Types

Before we can write code, we need to understand what kind of information we are working with. Imagine a warehouse where you store items in different types of boxes. You wouldn't put a liquid in a cardboard box, right? Data types are like those specific boxes.

Common Data Types

  • Integer: Whole numbers (e.g., 7, -12, 100). No decimals allowed!
  • Real/Float: Numbers with decimal points (e.g., 3.14, -0.01).
  • Boolean: Can only be True or False. Like a light switch.
  • Character: A single letter, number, or symbol (e.g., 'A', '$', '4').
  • String: A collection of characters. Usually text (e.g., "Hello World").
  • Date/Time: Specifically for calendar dates and clock times.
  • Pointer/Reference: This stores the memory address of where an object is kept. It doesn't store the data itself; it tells the computer where to find it.
  • Arrays: A collection of items of the same data type stored under one name.
  • Records: A collection of related data that can be of different types (like a student record containing a name, age, and ID).

User-Defined Data Types

Sometimes the built-in types aren't enough. You can create your own! This is called a user-defined data type. For example, you might create a "Point" type that stores two integers: \( x \) and \( y \).

Quick Review: Choosing the right data type is important because it tells the computer how much memory to set aside and what operations are possible (e.g., you can't multiply two strings!).

2. Programming Concepts & Control Structures

How does a program actually move from start to finish? There are three main principles: Sequence, Selection, and Iteration.

The Basics

  • Variable Declaration: Telling the computer "I need a box named score to hold an integer."
  • Constant Declaration: Like a variable, but the value cannot change while the program is running (e.g., PI = 3.14).
  • Assignment: Using the = sign to put a value into a variable (e.g., score = 10).

Selection (Decision Making)

This is how programs "think." We use IF statements or Switch/Case statements.
Example: IF score > 50 THEN "You Pass!" ELSE "Try Again!"

Iteration (Looping)

Iteration is just a fancy word for repeating code. There are two types:

  1. Definite Iteration: You know exactly how many times it will run (e.g., a FOR loop).
  2. Indefinite Iteration: It keeps going until a condition is met (e.g., WHILE or REPEAT UNTIL loops).

Common Mistake: In a WHILE loop, the condition is checked at the start. If the condition is false to begin with, the code inside might never run! In a REPEAT UNTIL loop, the code runs at least once because the check is at the end.

3. Arithmetic & Logical Operations

Programming involves a bit of math, but don't panic! It's mostly basic operations.

Arithmetic Operations

  • Addition (+), Subtraction (-), Multiplication (*)
  • Real/Float Division (/): Standard division (e.g., \( 5 / 2 = 2.5 \)).
  • Integer Division: This gives the whole number part and the remainder.
    • DIV: Quotient (e.g., \( 7 \text{ DIV } 2 = 3 \)).
    • MOD: Remainder (e.g., \( 7 \text{ MOD } 2 = 1 \)).
  • Exponentiation: Raising to a power (e.g., \( 2^3 = 8 \)).
  • Rounding vs. Truncation: Rounding goes to the nearest whole number; truncation just "chops off" the decimal part.

Relational & Boolean Operations

Relational operators compare things: = (equal), != or <> (not equal), < (less than), > (greater than).

Boolean operators combine truths:

  • AND: Both must be true.
  • OR: At least one must be true.
  • NOT: Flips the value (True becomes False).
  • XOR: Exclusively one or the other. If both are true, XOR is false!

4. Working with Strings

Think of a String as a necklace where each bead is a Character. We can manipulate these:

  • Length: How many characters? ("Cat" is 3).
  • Position: Finding where a letter is (remember, many languages start counting at 0!).
  • Substring: Taking a "slice" of a string.
  • Concatenation: Joining two strings together (e.g., "Fire" + "fly" = "Firefly").

Did you know? Computers don't actually know letters; they use Character Codes (like ASCII or Unicode). You can convert a character like 'A' into its code (65) and back again!

5. Subroutines (Procedures and Functions)

A Subroutine is a named block of code that performs a specific task. Instead of writing the same code 10 times, you write it once in a subroutine and "call" it whenever you need it.

Procedures vs. Functions

  • Procedures: They carry out a task but don't necessarily send a value back.
  • Functions: They must return a value back to the main part of the program.

Parameters and Scope

Parameters: These are pieces of data you pass into a subroutine so it can do its work (like the ingredients you give to a chef).

Local Variables: These only exist inside the subroutine. Once the subroutine finishes, they are deleted. This is "good practice" because it prevents different parts of your program from accidentally changing each other's data.
Global Variables: These can be accessed from anywhere in the program. Use them sparingly!

Key Takeaway: Using subroutines makes your code easier to read, test, and reuse. It’s like breaking a big project into small, manageable jobs.

6. The Stack and Recursion

This is a slightly more advanced topic, so don't worry if it takes a moment to click!

Stack Frames

When a program calls a subroutine, it needs to remember where it was so it can go back when it's done. It uses a Stack Frame to store:

  • Return Address: Where to go back to.
  • Parameters: The values passed in.
  • Local Variables: Data specific to that call.

Recursion

Recursion is when a subroutine calls itself.
Imagine standing between two mirrors—the image repeats forever. In code, we prevent this "forever" with a Base Case.

  • Base Case: The condition that stops the recursion.
  • General Case: The part where the function calls itself again.

Analogy: To find the bottom of a stack of boxes, if you aren't at the bottom (base case), look at the box below (recursive call).

Quick Review Box:
1. Sequence: Code runs in order.
2. Selection: IF/ELSE decisions.
3. Iteration: Loops (For/While).
4. Subroutines: Reusable blocks.
5. Local Variables: Safer than Global variables.

You’ve reached the end of the Fundamentals of Programming notes! Take a break, try writing a simple loop in your preferred language, and remember: every expert programmer started exactly where you are now. Keep coding!