Week 5 — Readings & Resources · Loops I: the `while` loop
Course: Introduction to Computer Science — CS1 / Programming Fundamentals in Python (CSCI 1101) · Silver Oak University (fictional sample) · Prof. Okafor
Objective covered: Objective 4 — Write while loops with counters and accumulators; trace a loop's final value and iteration count; diagnose and fix infinite loops and off-by-one errors.
How to use this page
Everything here is a link to an external resource — open it in your browser. Nothing needs to be downloaded or installed; the Python environments below run in the browser.
This week the fastest way to learn is to type a loop, predict how many times it runs, and run it to check. So keep the runner open and count the iterations as you read.
Order that matches the lecture: ① the
whileloop (condition + body) → ② counters & accumulators → ③ off-by-one (<vs<=) → ④ infinite loops, how to stop them, andbreak.
A habit to keep this week: never trust an iteration count you didn't run. Before you believe a page (or a chatbot) about how many times a loop runs, paste it into the runner and count the lines yourself. And if a loop ever seems stuck, press Ctrl+C (terminal) or Stop (online editor) — it's an infinite loop, not a broken computer.
① The while Loop — condition + body
Maps to Lecture Segments 2–3. A
whileloop repeats its indented body as long as a condition is true; each pass is one iteration.
Read & do — "Python while Loop" (Programiz)
🔗 https://www.programiz.com/python-programming/while-loop
Why it's assigned: the cleanest walk-through of the while loop — the condition, the body, a counting example, and a clear "infinite while loop" section and a break example, exactly this week's arc. Read it, then type its counting example into the runner and run it.
⏱ ~10 min
Read — "More Control Flow Tools" (official Python Tutorial, §4)
🔗 https://docs.python.org/3/tutorial/controlflow.html
Why it's assigned: the official docs, from the source of truth. For this week, focus on §4.4 break and continue (how to leave a loop early) — the while statement itself is introduced just before this chapter. Skim the rest; we'll return to for/range (§4.2–4.3) next week.
⏱ ~10 min
② Counters & Accumulators
Maps to Lecture Segment 3. A counter ticks up (
count = count + 1); an accumulator builds a runningtotal. Initialize before the loop, update inside it.
Interactive — "Python While Loops" (W3Schools)
🔗 https://www.w3schools.com/python/python_while_loops.asp
Why it earns the click: a friendly, click-through page with a green "Try it Yourself" button on every example, so you run each loop on the page. It shows the counting pattern and break. Do the examples, and after each, predict the count before you click Run.
⏱ ~10 min
Watch & do — "Your First Python Program / Run Python in your browser" (online editor)
🔗 https://www.online-python.com/
Why it earns the click: this is where you build your own counter and accumulator. Type the sum-1-to-5 loop from class (total = 0, i = 1, while i <= 5: total = total + i; i = i + 1; print(total) → it prints 15) and run it. (A second option, if you ever want it: 🔗 https://www.programiz.com/python-programming/online-compiler — same idea.)
⏱ ~5 min to build the accumulator yourself
③ Trace & Off-by-One · and ④ Infinite Loops + break
Maps to Lecture Segments 4–7. Predict a loop's final value and iteration count; learn the
<-vs-<=off-by-one; recognize and stop an infinite loop; usebreak.
See it run, step by step — Python Tutor
🔗 https://pythontutor.com/
Why it earns the click: the single best tool for understanding a loop. Paste a counter loop, click Visualize Execution, then step forward and watch the counter change and the condition flip to False. This is how the off-by-one stops being mysterious — you literally see i reach the boundary. (Used in CS classes at thousands of universities.)
⏱ ~6 min — step through i = 0; while i < 7: print(i); i = i + 1
Read & do — "Python break and continue" (Programiz)
🔗 https://www.programiz.com/python-programming/break-continue
Why it's assigned: short and practical — how break leaves a loop immediately (the manual STOP), including the common while True: ... break pattern from class. We use break this week; continue is a bonus you'll meet more next week.
⏱ ~5 min
Optional one-stop references (free online)
- The official Python Tutorial — index. Your reference all term; §4 is this week's home.
🔗 https://docs.python.org/3/tutorial/index.html - Programiz — "Getting Started with Python" (full Python tutorial index). A free, well-organized tutorial you can return to all term; the Flow Control section covers
if,while,for, andbreak/continuein order.
🔗 https://www.programiz.com/python-programming
Pick-one quick path (≈15 min total)
In a hurry? Do exactly these two and you'll be ready for the quiz:
1. Read "Python while Loop" on Programiz, then type its counting loop into online-python.com and run it — and count the iterations (groups ①–②).
2. Paste i = 0; while i < 7: print(i); i = i + 1 into Python Tutor and step through it — watch i climb to 7 and the loop stop. It prints 0–6, so it runs 7 times (groups ③–④).
Heads-up (links rot): these point to outside sites that occasionally move or rename pages. If a link ever fails, tell Prof. Okafor and use the official Python Tutorial (docs.python.org/3/tutorial) or W3Schools (w3schools.com/python) in the meantime.
~ Prof. Okafor's edition · Fall 2026 · built with thecoursemaker.com