# Programming From Zero

> What a program actually is, the building blocks every language shares (variables, types, operators), and how code makes decisions and reuses work with if/else, loops, and functions.


---

# Programming From Zero

You've decided to learn to code. Maybe you're switching careers, maybe you're curious, maybe a job
needs it. And right now code probably looks like a wall of symbols that everyone else seems to read
effortlessly - like there's a secret you missed on day one.

There's no secret. Code is a precise set of instructions you write for a computer, and the computer
follows them in order, doing exactly what you said and nothing else. Once you see it that way, the
symbols stop being intimidating and start being *readable*. This guide takes you from "I have never
written a line of code" to "I can read most code and understand what it's doing."

We'll use one friendly language - **Python** - for every example, because its code reads almost like
English. But the ideas you'll learn here are *universal*: variables, types, decisions, loops, and
functions exist in every language you'll ever touch. Learn them once, recognize them everywhere.

## How to read this

- **Brand new to all of this?** Read in order, start to finish. Each phase builds directly on the one
  before it, and nothing assumes knowledge you haven't been given yet.
- **Want to brush up one idea?** Jump to the phase you need - [variables and types](02-building-blocks.md),
  or [decisions, loops, and functions](03-control-flow-and-functions.md) - each stands on its own.

You don't need anything installed to follow along. You can read every example and understand it. When
you're ready to run code yourself, any free online Python editor (search "Python online") will do.

## The phases

1. **[What a Program Actually Is](01-what-a-program-is.md)** - code is a precise list of instructions a
   computer follows in order; your first real example, line by line.
2. **[The Building Blocks: Variables, Types & Operators](02-building-blocks.md)** - named boxes for
   values, the handful of types you'll use constantly, and the operators that work on them.
3. **[Making Decisions & Reusing Work: Control Flow & Functions](03-control-flow-and-functions.md)** -
   `if`/`else` for branching, loops for repeating, and functions: the single most powerful idea you'll
   learn as a beginner.

> This guide is about the universal ideas, taught through Python. The deeper Python-specific machinery
> - lists and dictionaries, files, classes and objects - is deferred so this guide stays a clear first
> climb rather than a doorstop. Two good next steps once you finish:
> [What Happens When Code Runs](/guides/what-happens-when-code-runs) and
> [Data Structures Explained](/guides/data-structures-explained).


---

# What a Program Actually Is

Before you write a single line, get the most important idea straight - almost everything that feels
scary about coding comes from a wrong picture of what's happening.

Here's the wrong picture: that the computer is *smart*, that it understands what you *meant*, that
there's some intelligence on the other side filling in your gaps. There isn't. Once you stop expecting
that, code gets dramatically less frustrating.

## The mental model: instructions, not spells

**What a program actually is.** A program is a list of instructions, written down in advance, that a
computer carries out one at a time, in order, from top to bottom. That's it. You are writing a recipe,
and the computer is the most literal cook imaginable.

The key word is *literal*. The computer does **exactly** what your instructions say - no more, no less.
It doesn't guess what you meant, skip a step because it seems obvious, or fix your mistake for you. Tell
it to do something nonsensical and it does the nonsensical thing (or stops and complains). That sounds
like a weakness, but it's what makes programming *learnable*: because the computer is perfectly
predictable, every behavior has a cause you can find.

📝 **Terminology.** *Code* is the instructions you write, in a language a computer can be made to
understand. A *program* is a complete set of those instructions that does something. A *programming
language* (we're using **Python**) is the specific vocabulary and grammar you write the instructions in.

💡 **Key point.** You are not casting spells and hoping. You are writing precise instructions for a
machine that follows them exactly. When something goes wrong, it's not magic failing - it's an
instruction that said something other than what you intended. That reframe alone will save you a hundred
frustrated hours.

## Picture how it runs

When you run a program, the computer starts at the first line and walks downward, doing each instruction
in turn:

```mermaid
flowchart TD
  L1["Line 1: do this first"] --> L2["Line 2: then do this"] --> L3["Line 3: then this"] --> L4["Line 4: then this"] --> More["... and so on, top to bottom, in order"]
```

Order matters enormously. If line 2 depends on something line 4 sets up, it won't work - the computer
reached line 2 before line 4 ever happened. Reading code is mostly tracing, in your head, what the
machine does at each line, in sequence.

## Your first program

The classic first instruction in any language is: **put some text on the screen.** In Python, the
instruction for that is `print`.

```python runnable
print("Hello, world!")
```
*What just happened:* `print` is an instruction that means "display this on the screen." The text you
want shown goes inside the parentheses, wrapped in quotation marks. When the computer runs this one
line, it shows:

```console
Hello, world!
```

That's a complete program. One instruction, carried out exactly. Here's the line broken into its pieces
- you'll see every one of them again and again:

```text
   print ( "Hello, world!" )
   ─────   ───────────────
     │            │
     │            └─ the value you're giving to print: the text to show.
     │               The quotes mark where the text starts and ends.
     │
     └─ the name of the instruction you're running ("print this").
```

📝 **Terminology.** Running an instruction like `print(...)` is called **calling** it, and the value you
put in the parentheses is called an **argument** - the thing you're handing to the instruction to work
with. Here the argument is the text `"Hello, world!"`.

## Order in action

Because the computer goes top to bottom, three `print` instructions run in the order you wrote them:

```python runnable
print("First")
print("Second")
print("Third")
```
*What just happened:* The computer ran line 1, then line 2, then line 3, producing one line of output
each, in that exact order:

```console
First
Second
Third
```

Swap the lines and the output swaps too. The computer has no opinion about what order makes sense - it
follows yours.

## The gotcha that bites every single beginner

⚠️ **The computer is unforgivingly literal about punctuation.** Leave off a quote, a parenthesis, or
misspell `print`, and the program doesn't "mostly work" - it stops and reports an error. For example,
forgetting the closing quote:

```python
print("Hello, world!)
```
*What just happened:* The computer started reading the text after the first quote and kept going,
looking for the closing quote that ends it - and never found one. It can't guess where you meant the
text to stop, so it gives up with a message like this:

```console
  File "hello.py", line 1
    print("Hello, world!)
          ^
SyntaxError: unterminated string literal (detected at line 1)
```

📝 **Terminology.** A **syntax error** means your code broke the grammar rules of the language - like a
sentence with no closing quotation mark. The computer can't even *run* it yet, because it can't make
sense of what you wrote.

This feels harsh at first, but notice what the error gives you: the file, the line number (`line 1`), a
little `^` pointing near the problem, and a description (`unterminated string literal` - "you opened a
piece of text and never closed it"). Errors aren't the computer being mean - they're it telling you,
precisely, where your instructions didn't make sense. Learning to *read* them calmly is one of the
biggest things separating someone who's stuck from someone who's moving.

## Why this saves you later

Every confusing moment ahead - a program that does the wrong thing, output that's out of order, a crash
you don't understand - comes back to this one idea: **the computer did exactly what you told it, in the
order you told it.** When code misbehaves, you don't ask "why is it broken?" You ask "what did I
actually tell it to do, line by line?" Then you trace it. That mindset is the entire job.

## Recap

1. A **program** is a list of instructions the computer follows **in order, top to bottom**.
2. The computer is **perfectly literal** - it does exactly what you wrote, never what you meant. That
   predictability is what makes bugs findable.
3. `print("...")` displays text on the screen; the text in quotes is the **argument** you hand it.
4. **Order matters** - rearrange the lines and you rearrange the output.
5. A **syntax error** means you broke the language's grammar (a missing quote or parenthesis); the error
   message points you at where.

Next, we give those instructions something to work *with*: named values, the types they come in, and the
operators that combine them.


---

# The Building Blocks: Variables, Types & Operators

In [Phase 1](01-what-a-program-is.md) you handed a fixed piece of text straight to `print`. Real
programs work with values that change - a username, a price, a score, an answer calculated a moment
ago - so the program needs a way to *hold onto* a value and refer to it later.

Three small ideas cover it, and you'll use all three in nearly every program you write: **variables**
(where values live), **types** (what kind of value it is), and **operators** (how you combine values).

## Variables: named boxes for values

**What a variable actually is.** A variable is a name you attach to a value so you can use it later.
Picture a labeled box: you put a value in the box, write a name on the label, and from then on you can
ask for the value by name.

```python runnable
age = 30
print(age)
```
*What just happened:* The first line created a box labeled `age` and put the value `30` inside it. The
second line asked `print` to show whatever is in the box called `age`. The computer looked it up and
displayed:

```console
30
```

Notice `print(age)` has no quotation marks around `age`. That's deliberate, and it's a distinction worth
locking in now:

- `print("age")` shows the literal text **age** (it's a fixed piece of text - see types below).
- `print(age)` shows **what's inside the box** named `age` - here, `30`.

Quotes mean "this exact text." No quotes mean "the value stored under this name."

**Variables can change** - that's why they're called *variable*. Put a new value in the box and it
replaces the old one:

```python runnable
score = 0
print(score)
score = 100
print(score)
```
*What just happened:* `score` started holding `0`, which we printed. Then we put `100` in the same box,
replacing the `0`, and printed again. The box's name stayed the same; its contents changed:

```console
0
100
```

📝 **Terminology.** Putting a value into a variable is called **assignment**, and `=` is the
**assignment operator**. Read `score = 100` as "set `score` to `100`," *not* as "score equals 100" in
the math sense - the difference matters, and you'll see exactly why at the end of this phase.

💡 **Key point.** A variable is just a name pointing at a value. Any bare word in code that isn't in
quotes and isn't a known instruction is almost always a variable - the real question is always "what's
currently inside it?"

## Types: what kind of value it is

Every value has a **type** - a category that tells the computer what the value *is* and what you're
allowed to do with it. You don't declare types in Python; the value's appearance decides its type.
Three types cover most of what a beginner does:

```text
   TYPE        WHAT IT IS                  EXAMPLES
   ─────────   ─────────────────────────   ────────────────────────
   number      a quantity you can do        30      3.14      -7
               math with                    (count, price, score)

   string      a piece of text, in quotes   "hello"   "Ada"   "30"
               (str for short)              (names, messages, labels)

   boolean     a yes/no, true/false value   True      False
               (bool for short)             (is it on? did it pass?)
```

📝 **Terminology.** A **string** is the programming word for "a piece of text" - always written inside
quotes. A **boolean** (named after logician George Boole) is a value that is either `True` or `False`,
nothing else. In Python they're capitalized and written without quotes - special values, not text.

Here's each type living in a variable:

```python runnable
name = "Ada"
age = 30
is_student = True
print(name)
print(age)
print(is_student)
```
*What just happened:* Three boxes, three different types of value - text, a number, and a boolean. The
computer happily holds all three and prints each one:

```console
Ada
30
True
```

**Why the type matters: `"30"` is not `30`.** A number in quotes is text, and the computer treats text
and numbers differently:

```python runnable
print(2 + 2)
print("2" + "2")
```
*What just happened:* On the first line, `2` and `2` are numbers, so `+` adds them: you get `4`. On the
second line, `"2"` and `"2"` are *strings* - text - so `+` glues them together end to end instead of
adding. You get the text `"22"`:

```console
4
22
```

The `+` symbol did two completely different jobs depending on the *type* of the values around it - type
is not a fussy detail, it changes what your instructions actually do. (Gluing strings together with `+`
is common and useful; it's called **concatenation**.)

⚠️ **Gotcha: a number typed by a user usually arrives as a string.** When a program reads input from a
person, it comes in as text, even if the person typed digits. Doing math on it without converting first
is one of the most common beginner stumbles - `"5" + "3"` gives `"53"`, not `8`. Convert with `int("5")`
(whole number) or `float("5.0")` (decimal). Just know the trap exists for now; you'll meet conversions
properly when you start reading real input.

## Operators: doing things with values

**What an operator actually is.** An operator is a symbol that takes one or two values and produces a
new value. You've already met two: `=` (assign) and `+` (add numbers, or glue strings). Two families
you'll use constantly:

### Math operators

These do exactly what you'd expect on numbers:

```python runnable
print(10 + 3)
print(10 - 3)
print(10 * 3)
print(10 / 3)
```
*What just happened:* Addition, subtraction, multiplication (`*`, not `×`), and division (`/`, not `÷`).
Each produces a new number, which we print:

```console
13
7
30
3.3333333333333335
```

That long decimal is real, not a typo - `/` always gives a decimal result, and 10 divided by 3 genuinely
doesn't end. The computer shows as many digits as it stores. (Don't worry about why it stops where it
does; it's a normal quirk of how computers hold decimals.)

Operators work on variables too, not just literal numbers - this is where they earn their keep:

```python runnable
price = 20
quantity = 3
total = price * quantity
print(total)
```
*What just happened:* The computer looked up the value in `price` (`20`) and in `quantity` (`3`),
multiplied them to get `60`, and stored that result in a new box called `total`. Then it printed `total`:

```console
60
```

Read `total = price * quantity` right to left: *first* the computer works out the value on the right
(`price * quantity`), *then* puts that result into the box on the left (`total`). Right side computed
first, then assigned to the left - that order holds for every assignment you'll ever write.

### Comparison operators

These compare two values and produce a **boolean** - `True` or `False`. This is how a program asks
questions about its values (and, in [Phase 3](03-control-flow-and-functions.md), makes decisions):

```text
   ==   equal to?                  5 == 5   →  True
   !=   not equal to?              5 != 3   →  True
   >    greater than?              5 > 3    →  True
   <    less than?                 5 < 3    →  False
   >=   greater than or equal?     5 >= 5   →  True
   <=   less than or equal?        3 <= 5   →  True
```

Watch one in action:

```python runnable
age = 30
print(age > 18)
print(age == 18)
```
*What just happened:* The computer looked up `age` (`30`), compared it, and produced a boolean for each
question. Is 30 greater than 18? Yes. Is 30 equal to 18? No:

```console
True
False
```

A comparison changes nothing - it just answers a question with `True` or `False`, which is the raw
material for every decision a program makes.

## The gotcha that confuses everybody: `=` vs `==`

⚠️ **`=` means *assign*. `==` means *compare*. They are completely different, and mixing them up is the
single most common beginner mistake.** Hold these two side by side:

```python
x = 5        # ASSIGN: put the value 5 into the box named x
x == 5       # COMPARE: ask "is what's in x equal to 5?" → produces True
```
*What just happened:* The first line *does* something - it sets `x` to `5`, silently, printing nothing.
The second line *asks* something - it checks whether `x` equals `5` and produces the boolean `True` (it
doesn't print on its own; you'd wrap it in `print` to see it).

This trips everyone up because in math class, `=` means "is equal to." In programming, plain `=` does
**not** mean that - it means "make this so." To *ask* whether two things are equal, you need the doubled
`==`. Reach for two equals signs to check equality, one to store a value.

🪖 **War story.** Nearly every programmer alive has written `if x = 5` (one equals) when they meant
`if x == 5` (two), then stared at the resulting error or wrong behavior in total confusion. You will do
it too. When a comparison isn't behaving, the very first thing to check is: did I use one `=` where I
needed two? It's such a reliable culprit that it's worth making it your reflex.

## Why this saves you later

Variables, types, and operators are the nouns and verbs of programming. Every program - the simplest
script and the largest app you'll ever see - is built from values held in variables, of some type, being
combined and compared with operators. When you read unfamiliar code, you're mostly tracing values
through boxes. When a program gives a wrong answer, the cause is almost always one of these three: the
wrong value in a box, a value of the wrong type (`"30"` where you needed `30`), or the wrong operator
(`=` where you meant `==`).

## Recap

1. A **variable** is a named box holding a value; `=` **assigns** a value into it, and the value can be
   replaced later.
2. Every value has a **type** - most often a **number**, a **string** (text, in quotes), or a **boolean**
   (`True`/`False`). The type changes what operators do (`2 + 2` is `4`; `"2" + "2"` is `"22"`).
3. **Math operators** (`+ - * /`) make new numbers; in `total = price * quantity` the right side is
   computed first, then stored on the left.
4. **Comparison operators** (`== != > < >= <=`) ask questions and produce a boolean.
5. ⚠️ **`=` assigns, `==` compares.** The most common beginner bug lives right here - check it first when
   a comparison misbehaves.

Now you have values and ways to combine them. Next we give the program a will of its own: the ability to
choose what to do, repeat work, and bundle instructions into reusable tools.


---

# Making Decisions & Reusing Work: Control Flow & Functions

So far your programs have been a straight line: the computer starts at the top, runs each instruction
once, and reaches the bottom. That's enough to *calculate*, but not enough to *behave*. Real programs do
different things in different situations, repeat work without copy-pasting it, and reuse the same logic
in many places.

Three ideas unlock all of that: **`if`/`else`** (choosing), **loops** (repeating), and **functions**
(reusing). The last one is the most important thing you'll learn as a beginner - saved for the end on
purpose.

## Making decisions with `if` / `else`

**What `if` actually is.** `if` lets the computer choose. You give it a condition - a question that comes
out `True` or `False` (comparison operators, from [Phase 2](02-building-blocks.md)) - and a block of
instructions. The computer runs that block **only if** the condition is `True`; if it's `False`, it
skips the block.

```python runnable
temperature = 35
if temperature > 30:
    print("It's hot out. Drink water.")
```
*What just happened:* The computer evaluated the condition `temperature > 30`. Since `temperature` is
`35`, the condition is `True`, so it ran the indented line. Output:

```console
It's hot out. Drink water.
```

If `temperature` had been `20`, the condition would be `False`, the indented line would be skipped, and
the program would print nothing at all.

Two pieces of grammar are doing real work here, and they confuse beginners until someone points them out:

- **The colon (`:`)** at the end of the `if` line means "here comes the block of instructions that
  belongs to this `if`."
- **The indentation** (the spaces before `print`) is how Python knows which lines are *inside* the `if`.
  Indented lines belong to it; un-indented lines come after and run regardless.

📝 **Terminology.** This family of features - `if`, loops, functions - is called **control flow**,
because it controls the *flow* of execution: which instructions run, in what order, how many times.
Plain top-to-bottom is one path; control flow lets you branch off it.

### `else` and `elif`: the other paths

`if` alone handles "do this when true, otherwise do nothing." Often you want "do this, *otherwise* do
that" - that's `else`. For more than two paths, `elif` ("else if") checks another condition:

```python runnable
score = 72
if score >= 90:
    print("Grade: A")
elif score >= 70:
    print("Grade: B")
else:
    print("Grade: C or below")
```
*What just happened:* The computer checked the conditions top to bottom and took the **first** one that's
`True`, then skipped the rest. `score >= 90`? No (72 is not ≥ 90). `score >= 70`? Yes - so it printed
"Grade: B" and ignored the `else` entirely:

```console
Grade: B
```

That "first match wins, then stop" behavior is the whole point: exactly one branch runs, never two. Order
them carefully - if you'd checked `>= 70` before `>= 90`, a 95 would match the `>= 70` branch first and
never reach the A.

## Repeating work with loops

**What a loop actually is.** A loop runs the same block of instructions more than once. Without loops,
printing the numbers 1 through 5 means writing five `print` lines. With a loop, you write the instruction
once and tell the computer how many times to do it.

The most common loop, the `for` loop, walks through a sequence of values, running its block once per
value:

```python runnable
for number in range(1, 6):
    print(number)
```
*What just happened:* `range(1, 6)` produces the numbers 1, 2, 3, 4, 5 (it starts at the first value and
stops *before* the second - more on that in a second). The loop ran its indented block once per number,
each time putting the current number into the variable `number`. Five passes, five lines of output:

```console
1
2
3
4
5
```

The same colon-and-indentation grammar from `if` applies: the `:` introduces the block, and the indented
lines are what gets repeated.

⚠️ **Gotcha: `range(1, 6)` stops *before* `6`, not at it.** This catches everyone. `range(start, stop)`
includes `start` but excludes `stop` - so `range(1, 6)` gives you 1 through 5, and `range(0, 3)` gives
you 0, 1, 2. Want 1 through 10? Write `range(1, 11)`. The "stops before the end" rule shows up all over
programming; meet it now and it'll surprise you less later.

Loops aren't just for counting - their real value is doing real work many times. Here's summing a list
of numbers:

```python runnable
prices = [10, 25, 5]
total = 0
for price in prices:
    total = total + price
print(total)
```
*What just happened:* Starting with `total` at `0`, the loop ran once per value in `prices`: `10` makes
`total` `10`, then `25` makes it `35`, then `5` makes it `40`. After the loop finished, we printed the
final `total`:

```console
40
```

📝 **Terminology.** `prices = [10, 25, 5]` is a **list** - an ordered collection of values held in one
variable. Lists are how programs hold "many things," and looping over them is how programs process those
things one by one. (Lists have a lot more to them; that's a topic for
[Data Structures Explained](/guides/data-structures-explained).)

💡 **Key point.** A loop is the cure for copy-paste. Any time you'd be writing nearly the same line over
and over, that's a loop waiting to happen. Write the work once; let the loop repeat it.

## Functions: the most powerful idea you'll learn

Here it is - the idea that does more for a beginner than any other.

**What a function actually is.** A function is a named, reusable block of instructions. You define it
once, giving it a name and the steps it should perform. Then, anywhere you want those steps to run, you
**call** the function by its name, and the computer jumps to the block, runs it, and comes back. You
already met one: `print` is a function someone else wrote that you call. Now you'll write your own.

Why does this matter so much? It lets you name a piece of work and reuse it without repeating yourself.
Think of a function as a recipe card: written once, followed any number of times, without re-explaining
the steps.

```python runnable
def greet():
    print("Hello!")
    print("Welcome to the program.")

greet()
greet()
```
*What just happened:* The `def greet():` block **defined** a function named `greet` - but defining it
doesn't run it; it just teaches the computer the steps. The two `greet()` lines at the bottom **called**
it. Each call ran the function's two `print` lines, so the greeting appeared twice:

```console
Hello!
Welcome to the program.
Hello!
Welcome to the program.
```

📝 **Terminology.** `def` (short for "define") starts a function definition. The name is followed by
parentheses `()` and a colon, and the indented lines beneath are the function's **body** - the
instructions it runs when called. Defining ≠ running: the body only runs when you *call* the function by
name with parentheses.

### Inputs and outputs: parameters and `return`

A function that does the exact same thing every time is useful, but the real power is feeding it
**inputs** and getting a **result** back.

- An **input** is a value you hand the function when you call it (an *argument*, like the text you give
  `print`). Inside the function, that value lands in a named slot called a **parameter**.
- A **result** is a value the function hands back to you, using the `return` instruction.

```python runnable
def add(a, b):
    result = a + b
    return result

answer = add(10, 5)
print(answer)
```
*What just happened:* We called `add(10, 5)`. The computer jumped into the function, putting `10` into
the parameter `a` and `5` into `b`. It calculated `a + b` (`15`), stored it in `result`, and `return`
**handed that value back** to the place that called it. Back outside, `add(10, 5)` became `15`, which we
stored in `answer` and printed:

```console
15
```

`return` is the function's way of *answering*. When the computer hits `return`, it stops the function
immediately and sends that value back to whoever called it. A function with `return` can be used anywhere
you'd use a value - stored, printed, compared, or fed into another function.

⚠️ **Gotcha: `print` and `return` are not the same thing, and confusing them is extremely common.**
`print` puts text on the screen for a *human* to read and hands nothing back to the program. `return`
gives a value back to the *program* so it can keep using it, and puts nothing on the screen. A function
that `print`s its answer but doesn't `return` it can't have that answer used in the next calculation -
it was shown and then thrown away. When a function "works when I print inside it but breaks when I try
to use the result," this is almost always why.

## Putting it all together

Here's a tiny but complete program using every idea from this guide at once. Read it top to bottom, the
way the computer does - you should be able to follow every line:

```python runnable
def grade_for(score):
    if score >= 90:
        return "A"
    elif score >= 70:
        return "B"
    else:
        return "C or below"

scores = [95, 72, 40]
for score in scores:
    letter = grade_for(score)
    print(score, "->", letter)
```
*What just happened:* `grade_for` takes a `score`, uses `if`/`elif`/`else` to decide a letter grade, and
`return`s it. We made a list of three scores and looped over them - for each one, called `grade_for`,
stored the returned letter, and printed the score next to its grade:

```console
95 -> A
72 -> B
40 -> C or below
```

Look at what's working together: a **variable** holds each score; **types** (numbers, strings, the
booleans the comparisons produce) flow through it; **operators** (`>=`) ask the questions;
**`if`/`elif`/`else`** chooses the path; a **loop** repeats the work for every score; and a **function**
bundles the grading logic so it's written once and reused three times. That's not a toy - that's the
shape of real programs. Bigger ones are this, repeated and combined.

## You can now read most code

Take a breath - you've crossed a real line. The five ideas you now hold - values in variables, their
types, operators to combine them, control flow to choose and repeat, and functions to reuse - are the
load-bearing structure of *every* program. Languages differ in punctuation and vocabulary, but open
almost any codebase and you'll see these same five things arranged differently.

You won't understand every line of every program yet - there's plenty more (lists and dictionaries in
depth, files, organizing big programs with classes). But you can now read a block of code, trace what it
does line by line, and reason about it instead of fearing it. That's the skill - everything else is more
vocabulary built on this exact grammar.

## Recap

1. **`if` / `elif` / `else`** run a block based on a condition; the **first** true branch wins and the
   rest are skipped. The `:` and indentation define which lines belong to the block.
2. **Loops** (`for ... in ...`) repeat a block once per value - the cure for copy-paste. ⚠️ `range(1, 6)`
   stops *before* 6, giving 1–5.
3. A **function** (`def name():`) is a named, reusable block of instructions you **call** by name;
   defining it doesn't run it.
4. Functions take **inputs** (arguments landing in parameters) and hand back a **result** with `return`.
   ⚠️ `print` shows a value to a human; `return` gives it back to the program - not the same thing.
5. Real programs are these ideas - variables, types, operators, control flow, functions - combined. You
   can now read them.

## Where to go next

- **[What Happens When Code Runs](/guides/what-happens-when-code-runs)** - the next layer down: what the
  computer actually does with your instructions when you press "run."
- **[Data Structures Explained](/guides/data-structures-explained)** - lists, dictionaries, and the other
  ways programs organize many values at once.

Watch it animated: [conditional branching](/explainers/ConditionalBranching.dc.html)
