Dashboard/Block 1: Foundation/Module 2
Module 2Foundation

Control Flow & Functions

So last week, your programs were pretty straightforward — they just ran from the first line to the last line, one after the other. Every single instruction got executed exactly once. But think about it... real programs do not work that way, right? They need to make choices — like "if this user is old enough, let them in, otherwise show an error." And they need to repeat things — like "keep asking for a password until they get it right."

That is what this week is all about. We are learning two of the most powerful ideas in programming: conditional statements (making decisions) and loops (repeating things). On top of that, we will get into functions — which are basically reusable chunks of code that you give a name to. Instead of copy-pasting the same code everywhere, you write it once, put it in a function, and just call it whenever you need it. We will even touch on recursion — which is when a function calls itself. Sounds wild, but it is actually a really elegant way to solve certain problems.

ConceptWhat It DoesReal-World Analogy
if/elseMakes decisions based on conditionsA traffic light — go if green, stop if red
for loopRepeats code a known number of timesCounting laps around a track
while loopRepeats code until a condition becomes falseStirring soup until it boils
FunctionA reusable block of code with a nameA recipe you can follow whenever you need it
RecursionA function that calls itselfRussian nesting dolls — each doll contains a smaller version of itself

Learning Objectives

Write conditional statements with if, else if, and else
Use for and while loops for repetition
Create and call your own functions
Understand function parameters and return values
Grasp the basics of recursion

Key Concepts

Control Flow: if/else and switch

Loops: for, while, do-while

Functions