Weeks 05–08 — Control Flow & Functions (Stage B)

Repetition, then decomposition — the two powers that turn scripts into programs. Week 5 carries the course’s first flagship project. ← Weeks 1–4 · Roadmap home · Weeks 9–12 →


Week 5 — Loops I — 🏁 Project 1

Session 5.1 — while, trace tables, and sentinels

Part Details
Prerequisites Week 4 — decisions and compound conditions fluent
Learning objectives write while loops with correct entry/update/exit; trace loops in a table before running; build sentinel-controlled and validation loops; recognize the infinite-loop shapes on sight
Concepts while, accumulators, counters, sentinel values, input-controlled loops, infinite loops and their causes, dry-run tables
Recommended reading Repetition Lesson 1 — while
Examples to study Lesson 1’s worked loops — trace each in a table before compiling
Exercises repetition exercises (while part) · Practice Bank B-31–B-38 (loops)
Lab/practice repetition labs — Labs 1–2
Challenge Practice Bank B-37 — running maximum from a stream
Estimated self-study time 90 min
Completion checklist ☐ 5 trace tables drawn on paper ☐ 2 labs done ☐ can list the three ingredients every correct loop needs

Session 5.2 — do-while, validation loops, and Project 1

Part Details
Prerequisites Session 5.1
Learning objectives choose do-while when one pass is guaranteed; build re-prompting validation loops; write the Project 1 calculator with a repeat-until-quit structure
Concepts do-while, menu skeletons, validation loops, program structuring for projects
Recommended reading Repetition Lesson 2 — for (skim ahead — for arrives next week) · Project 1 brief (Stage B: Electricity Bill Calculator) · Projects collection #1 as the self-study rehearsal
Examples to study Lesson 2’s early examples · the project brief’s sample runs
Exercises Practice Bank B-32, B-40 · repetition debugging D1–D2
Lab/practice 🏁 Project 1 — Electricity Bill Calculator — follow the milestones; use the test plan; score with the rubric
Challenge Project 1’s extension ideas (tiered tariffs, billing history)
Estimated self-study time 120 min (project week)
Completion checklist ☐ Project 1 submitted to yourself: all milestones, test plan passed, rubric self-scored ≥ Proficient ☐ re-prompt loop written from memory ☐ W05 quiz ≥ 90%

Week 6 — Loops II

Session 6.1 — for, break, and continue

Part Details
Prerequisites Week 5 — while and sentinels fluent
Learning objectives write counting for loops over arbitrary ranges; choose between while/for/do-while by the problem’s shape; control flow with break and continue
Concepts for anatomy, counting down, step sizes, break, continue, loop selection criteria
Recommended reading Repetition Lesson 2 — for · Lesson 3 — break/continue/sentinels
Examples to study both lessons’ worked examples · repetition predictions
Exercises Practice Bank B-33, B-34, B-36 · repetition exercises (for part)
Lab/practice repetition labs — Lab 3
Challenge Practice Bank Ba-06 — Collatz steps
Estimated self-study time 75 min
Completion checklist ☐ loop-choice rule stated in your own words ☐ predictions ≥ 8/10 ☐ Lab 3 done

Session 6.2 — Nested loops, digits, and patterns

Part Details
Prerequisites Session 6.1
Learning objectives trace and write nested loops; process digits with peel loops; print shape patterns with dependent inner bounds; multiply via nested accumulation
Concepts nested loops, inner/outer pass counting, digit processing (% 10, / 10), pattern printing, multiplication tables
Recommended reading Repetition Lesson 4 — Nested Loops, Digits, and Patterns
Examples to study Lesson 4’s pattern gallery — reproduce the triangle and the table from scratch
Exercises Practice Bank B-39, Ba-11–Ba-20 (patterns & digits) · repetition exercises (nested part)
Lab/practice repetition labs — pattern + number-properties labs
Challenge Practice Bank Ba-18 — Armstrong numbers in a range
Estimated self-study time 90 min
Completion checklist ☐ two patterns + one table printed without reference ☐ digit-peel loop written from memory ☐ W06 quiz ≥ 90%

Week 7 — Functions I

Session 7.1 — The function machine

Part Details
Prerequisites Week 6 — loops fluent
Learning objectives define, declare, and call functions; distinguish parameters from arguments; write void and value-returning functions; explain why decomposition beats one giant main
Concepts function declaration/definition/call, parameters vs arguments, return values, void, prototypes, call flow
Recommended reading Functions Lesson 1 — the machine
Examples to study Lesson 1’s call-flow diagrams — trace two calls on paper, box by box
Exercises Practice Bank Ba-21–Ba-25 · functions exercises (first part)
Lab/practice functions labs — first two
Challenge Practice Bank Ba-27 — scope shadowing demonstration
Estimated self-study time 75 min
Completion checklist ☐ two call traces drawn ☐ 5 function problems attempted ☐ 2 labs done

Session 7.2 — Scope, lifetime, and decomposition

Part Details
Prerequisites Session 7.1
Learning objectives explain local vs global scope and lifetime; write multi-function programs where main only coordinates; refactor an existing loop-heavy program into functions
Concepts local variables, global variables (and why the course bans new ones), scope shadowing, top-down decomposition, main-as-coordinator
Recommended reading Functions Lesson 2 — scope
Examples to study Lesson 2’s refactor walkthrough
Exercises Practice Bank Ba-30, Ba-37 · functions exercises (scope part)
Lab/practice functions labs — decomposition lab
Challenge functions challenges — first two
Estimated self-study time 75 min
Completion checklist ☐ one program refactored behavior-preserving ☐ can state the course’s globals rule and its reason ☐ W07 quiz ≥ 90%

Week 8 — Functions II

Session 8.1 — References and out-parameters

Part Details
Prerequisites Week 7 — function mechanics fluent
Learning objectives pass by reference with &; build multi-result functions with out-parameters; contrast pass-by-value and pass-by-reference from live examples
Concepts reference parameters, out-parameters, value vs reference semantics, swap-through-function
Recommended reading Functions Lesson 3 — references & testing
Examples to study Lesson 3’s value-vs-reference demonstration — reproduce both versions
Exercises Practice Bank Ba-35, Ba-36 · functions exercises (references part)
Lab/practice functions labs — statistics lab
Challenge Practice Bank Ba-38 — factorial both ways
Estimated self-study time 75 min
Completion checklist ☐ swap-by-reference written from memory ☐ one multi-out-param function designed and tested

Session 8.2 — Overloading, default arguments, and refactoring

Part Details
Prerequisites Session 8.1
Learning objectives overload functions by parameter list; use default arguments; test functions with drivers and stubs; complete a behavior-preserving refactor of a full program
Concepts function overloading, default arguments, drivers, stubs, testing functions, refactoring discipline
Recommended reading Functions Lesson 4 — overloading & refactoring · functions refactoring page
Examples to study the refactoring page’s before/after pairs
Exercises functions refactoring exercises · Practice Bank Ba-28, Ba-29, Ba-39, Ba-40
Lab/practice functions labs — remaining labs + functions miniproject (menu toolkit, milestones 1–3)
Challenge functions challenges — one more
Estimated self-study time 90 min
Completion checklist ☐ refactor completed behavior-identical ☐ mini-project milestones 1–3 ☐ Stage B checkpoint: W08 quiz ≥ 90% — Stage C unlocks

Next: Weeks 09–12 — Data structures and algorithms → · Roadmap home