← Back to the Introduction to Computer Science outline The Course Maker
← Introduction to Computer Science outline
Week 5 · Module overview

Week 5 — Loops I: The while Loop

Introduction to Computer Science Free sample edition

Welcome to your Week 5 Start Here page.

Why this matters

A health-science student whose step counter keeps adding until a daily target is met and a business major totalling a receipt one item at a time both depend on a loop that repeats, counts its passes, and stops at the right moment.

In plain language

So far every program you wrote ran each line once, from top to bottom, and stopped. This week your programs learn to repeat. A while loop (a block of code that runs again and again for as long as a test comes out True) lets one short program count days, add up totals, or keep trying until something works. You will learn to predict three things about every loop: what it prints, how many times it repeats, and where its counter (a name that goes up by one each time around) ends. You will also learn to spot a loop that never stops, and how to stop it.

  • Already covered: Week 3's input and f-strings and Week 4's comparisons and if.
  • This week: the while loop, counters, the off-by-one error, infinite loops, and break.
  • How they connect: every loop condition is a Week 4 comparison that Python tests again and again.
  • Where we're going next: Week 6, Loops II: for, range & Nested Loops.

Focus

How do I make a program repeat, and how do I make sure it stops at the right moment?

By the end of this module, you should be able to:

  • [ ] predict a while loop's output, passes, and counter's final value
  • [ ] fix an off-by-one error by testing the edge value
  • [ ] stop an infinite loop and add its missing update

To-do

Plan your week

  1. Read Chapter 5 (about 40 minutes), then the lecture and slides.
  2. Work the lecture tutorial (60–90 minutes) and the practice set (about 20 minutes).
  3. Do the Coding Lab (about 90 minutes), the discussion, and the assignment.
  4. Take the quiz.

This week's checkpoint: trace a while loop one pass at a time and say why the reading log stops at 315, not 300.

You've got this

Predict, then run, and ask your instructor if a step snags.

Built with The Course Maker · samples.thecoursemaker.com