Week 5 — Module Framing · Loops I: the `while` loop
Course: Introduction to Computer Science — CS1 / Programming Fundamentals in Python (CSCI 1101) · Silver Oak University (fictional sample) · Prof. Okafor
Module: Week 5 of 16 · Fall 2026 · in-person, two 75-minute coding-along studio sessions
Objective covered: Objective 4 — Use while (and, next week, for) loops: write loops with counters and accumulators, trace how many times a loop runs, and find and fix loop bugs.
This file holds two pieces: (A) the Module 5 Overview page ("Start Here") and (B) the Welcome Announcement that drips out when the module opens. Dates below assume a Tuesday/Thursday pattern with Week 5 meeting Tue Sep 29 and Thu Oct 1, a Coding Lab that same week, and end-of-week work due Sunday Oct 4, 11:59 p.m. Adjust the day-of-week and times to match your section.
(A) Module 5 Overview — Start Here
Welcome to Week 5: Loops I — the while loop
This is your home base for the week. Read it first, then work the checklist below from top to bottom. Everything you need is linked inside the module.
For four weeks your programs ran each line once, top to bottom. This week they learn to repeat. The while loop runs a block of code over and over, as long as a condition stays true — which is exactly the kind of True/False condition you mastered in Week 4. With repetition you get two of the most useful patterns in all of programming: a counter that ticks up (count = count + 1), and an accumulator that builds a running total. You'll also meet the loop's most famous failure — the infinite loop, where you forget to update the counter and the loop never stops — and learn exactly how to stop one (Ctrl+C) and how to fix it. The habit that carries the week: when you're not sure how many times a loop runs or what it adds up to, don't guess — run it and read what Python actually prints.
The week's big question
"How do you make a program repeat — and how do you make sure it eventually stops?"
By Friday you'll be able to write a while loop with a counter and an accumulator, predict the final value and the number of iterations of a loop before you run it (then check by running it), explain the off-by-one difference between < and <=, and spot-and-fix an infinite loop.
By the end of this week, you can…
Use this as a checklist. If you can do all four, you're ready for the quiz.
- [ ] Write a
whileloop with a condition and a body, including a counter (count = count + 1) and an accumulator (a runningtotal). - [ ] Trace a loop — predict its final counter value and how many times it runs, then run it to confirm (watch the off-by-one gap between
<and<=). - [ ] Diagnose an infinite loop — recognize a missing counter update, explain why the loop never stops, and stop it (
Ctrl+C) and fix it. - [ ] Use
breakto leave a loop early when a condition is met.
What's due this week, and when
Work these in order — each one gets you ready for the next.
| # | Do this | Type | Due |
|---|---|---|---|
| 1 | Read the week's readings + watch the linked videos | Read / watch (ungraded prep) | Before Thu Oct 1 |
| 2 | Skim the slides (Deck 5) and the Week 5 lecture outline | Prep (ungraded) | Alongside class |
| 3 | Lecture Tutorial 5 — work through while loops, counters, accumulators, off-by-one, and infinite loops with one approved chatbot (Gemini, Claude, or ChatGPT), then submit the conversation share link |
Lecture Tutorial · graded (5% group) | Sun Oct 4, 11:59 p.m. |
| 4 | Practice exercises — low-stakes reps to lock in the ideas | Practice · ungraded | Sun Oct 4 (recommended) |
| 5 | Coding Lab 5 — "Count, Total, Stop" — write a counter + accumulator loop, fill a predict-then-run table for several while loops, fix an infinite-loop / off-by-one bug, and visualize a counter loop stepping in Python Tutor — then catch the AI miscounting a loop's iterations |
Coding Lab · graded (Coding Labs, 15% group) · 50 pts | Sun Oct 4, 11:59 p.m. |
| 6 | Quiz 5 — covers while loops, predict-the-final-value/iteration-count, off-by-one, and infinite-loop debugging |
Quiz · graded (Quizzes, 10% group) | Sun Oct 4, 11:59 p.m. |
| 7 | Discussion 5 — "How Do You Actually Find the Bug?" — take a position in the debugging-strategy debate (print statements vs. Python Tutor vs. rubber-duck) in a dialogue with one approved chatbot, then post the AI summary + your chat link and reply to two classmates | Discussion · graded (Discussions, 10% group) | Initial post Fri Oct 2; replies Sun Oct 4 |
| 8 | Assignment 5 — "Loops That Count" — write a counter/accumulator loop, predict a loop's output, trace iterations, and fix an infinite-loop or off-by-one bug, coached and scored by one approved chatbot | Assignment · graded (Assignments, 15% group) · 100 pts | Sun Oct 4, 11:59 p.m. |
Heads-up on the AI tools: you'll use a chatbot as a pair-programmer to draft and explain — and then you check its work by running the code. Chatbots are surprisingly bad at loops: they miscount how many times a loop runs and get the off-by-one between < and <= wrong, with total confidence. Catching that — by running the code and reading the real output — is the point, in the tutorial, the assignment, and the lab.
How to succeed this week
- Run everything — but never run an actual infinite loop on purpose without a way to stop it. If a loop seems stuck, press Ctrl+C in a terminal (or click Stop in the online editor) to interrupt it. Then find the missing counter update.
- Two tiny hooks to memorize. "Every loop needs three things: a start, a stop, and a step." And "
< nstops one short ofn;<= nincludesn." - Predict, then check. Before you run a loop, say out loud (a) what its final value will be and (b) how many times it runs. Then run it. When the count is off by one, that gap is the lesson.
- Trace on paper first. For a short loop, write the counter's value on each pass in a little table. Watching the number change is how looping stops feeling like magic.
- Treat the chatbot as a smart intern, not an oracle. Ask it "how many times does this loop run?" — then run the loop and count. It is wrong often enough that catching it is a weekly skill.
You don't need any setup for this week — the Python environment runs in your browser, nothing to install. Come to class ready to make a program count to ten (and to stop it before it counts to infinity). See you Tuesday.
(B) Welcome Announcement — Module 5
Release setting: post on the module's start day (offset = 0 days), i.e., Tue Sep 29, 2026 — not before. If your platform won't preserve the scheduled date on import, post this as a draft labeled "Release: Tue Sep 29."
Subject: Week 5 — this week your code learns to repeat (and how to stop it) 🔁
Hi everyone,
For four weeks our programs ran straight through, each line once. This week they start to repeat. Meet the while loop: it runs a block of code over and over as long as a condition is true — built directly on the True/False conditions you learned last week.
This week — Loops I: the while loop — we tackle the big question: How do you make a program repeat, and how do you make sure it eventually stops? By Friday you'll write a loop with a counter and an accumulator (a running total), predict how many times a loop runs (then check by running it), and diagnose the most famous loop bug of all — the infinite loop.
Three things not to miss:
1. Lecture Tutorial 5 — work through while loops, counters, accumulators, the <-vs-<= off-by-one, and infinite loops with one approved chatbot (Gemini, Claude, or ChatGPT) and submit the share link. You'll use it as a pair-programmer — and catch its mistakes by running the code. Due Sun Oct 4.
2. Coding Lab 5 ("Count, Total, Stop"), Quiz 5, Discussion 5, and Assignment 5 also close Sun Oct 4 — the lab is where you write counter/accumulator loops and fix a loop bug, so start early.
3. Open the Start Here page first — it lays out everything in order with due dates.
One safety note for the week: if a loop ever seems stuck (it's printing forever, or just hanging), that's probably an infinite loop — you forgot to update the counter. Press Ctrl+C in a terminal, or click Stop in the online editor, to interrupt it. Nothing is broken; the loop just never reached its stopping condition. Finding the missing count = count + 1 is exactly the skill this week.
And the habit, as always: never trust an output you didn't run. Ask a chatbot "how many times does this loop run?" and it will confidently tell you a wrong number. In this course, the source of truth is the same as ever — run the code and read what Python actually prints.
Bring your curiosity (and a willingness to be off by one) to class on Tuesday.
See you soon,
Prof. Okafor
~ Prof. Okafor's edition · Fall 2026 · built with thecoursemaker.com