1. The Five Basic Terms
Why this page exists
Every page in this course uses five words. If you already write code, this page will take you two minutes and you can skip to the next one. If you have never written code, read it slowly. Nothing later depends on anything except these five words.
Word 1 — a variable
A variable is a labelled box that holds one thing. You pick the label.
total = 0Read that as: "there is a box called total, and right now it holds 0." Later you can put something else in the box. The label stays, the thing inside changes. That is all a variable is.
Word 2 — a list (an array)
Sometimes you have many things, not one. So you make a row of numbered boxes and put one thing in each. Programmers call this row an array (or a list). Here is a row of five prices:
Two things trip people up:
- Counting starts at 0. The first box is box 0, the second is box 1, and so on. Think of the box number as "how many steps from the start". The first box is zero steps away. A row of 5 boxes has box numbers 0 to 4.
- The box number is called the index. "The element at index 2" just means "what is in box number 2". We write it
prices[2].
When we say a list has N items, N is just a stand-in for "however many boxes there are". Five today, a million tomorrow.
Word 3 — a loop
A loop means: do this for each box. Instead of writing "look at box 0, look at box 1, look at box 2…" you write it once and the computer repeats it.
for each price in prices: look at the priceThe computer walks the row, one box at a time, left to right. That walk is one of the most important pictures in this course. Almost every idea we teach is a smarter way to walk a row of boxes.
Word 4 — an if
An if means: only do this when something is true.
if price > biggest: biggest = price"If this price is bigger than what is in the biggest box, put this price in the biggest box." Otherwise do nothing and move on.
Word 5 — a function
A function is a named recipe. You give it something, it does its steps, and it hands back an answer. Once you have written the recipe, you can use it as often as you like by saying its name.
recipe find_biggest(prices): ...steps... hand back the answerProgrammers say "call the function", "pass in the list", and "return the answer". Same thing: use the recipe, give it the list, hand back the result.
All five together
Let's find the biggest price in the row. Say it in plain words first:
Keep a box called
biggest. Start it with the first price. Walk the row. Whenever you see a price bigger than the box, put that price in the box. When the walk ends, whatever is in the box is the answer.
Watch it happen:
Now the same recipe as real code. Pick whichever language you like — they all say exactly the same thing.
The five words in one recipe
Read the code next to the plain words. Every line of code is one of the five words: a variable, a list, a loop, an if, and a function around the whole thing.
One more idea: a step
Each time the computer looks at a box, compares two numbers, or writes into a box, call that one step. Finding the biggest price in a row of 5 took about 5 steps. In a row of a million it would take about a million steps.
Counting steps is how we say whether a method is fast or slow. That is the whole next page.
Practice
There is nothing to solve yet. Do the quiz above, then move on to Big-O: Measuring Speed. If any of the five words still feels fuzzy, read its section once more — everything after this leans on them.
In the room
Interviewers never test these five words directly. They assume them. What they will notice is whether you use the words confidently: "I'll keep a variable for the running best, loop through the array once, and return it." That sentence uses all five, and it is exactly the kind of sentence this course will teach you to say without thinking.