---
title: "Count-Controlled Loops"
description: "Repeating a block a known number of times, with a loop variable that takes each value of a range in turn."
canonical: https://lightmysky.com/learn/computing/count-controlled-loops-mt_r1eXTWI_6j
source: https://lightmysky.com/learn/computing/count-controlled-loops-mt_r1eXTWI_6j.md
retrieved: 2026-09-12
---

> **Agent view.** This is the Markdown twin of the page, for tools and assistants.
> When to use this site, and the call that answers each job: https://lightmysky.com/agent-instructions.md
> API description (OpenAPI 3.1): https://lightmysky.com/openapi.json · Authentication: https://lightmysky.com/auth.md
> Pricing: https://lightmysky.com/pricing.md · Catalog: https://lightmysky.com/llms.txt · Full catalog: https://lightmysky.com/llms-full.txt
> Every machine-readable file on this domain: https://lightmysky.com/.well-known/ai-catalog.json
> Ask for Markdown with `Accept: text/markdown`, a `.md` address, or `?mode=agent`.

# Count-Controlled Loops

Repeating a block a known number of times, with a loop variable that takes each value of a range in turn.

Subject: Computing · Area: Programming · Ages 14 to 16
Page: https://lightmysky.com/learn/computing/count-controlled-loops-mt_r1eXTWI_6j

## Ready when they can

- Write a loop that repeats a fixed number of times
- Use the loop variable inside the body, for example to print a times table
- Say how many times a loop over a given range will run, before running it

## Lesson: Loops that know when to stop

A for loop repeats its block once for every item in a group, like the numbers from range(). Each pass hands the loop variable the next number, and the body runs once for it. Since you know the group up front, you know the repeat count before the loop starts.

**Example.** Printing the 9 times table needs 13 lines without a loop, one per multiple from 0 to 12. A loop does it in two lines: for each i in range(13), print 9 times i. Your 7 times table works the same way with range(13).

range() takes a start, a stop and a step, where the start counts but the stop never prints. So range(10, 26, 5) gives 10, 15, 20 and 25, which is 4 passes. Use the loop variable inside the body, and the loop ends exactly when the count says it will.

**Tip.** Say the repeat count aloud before you run anything. If the loop counts down, check that each step moves toward the stop, or it will never finish.

**Recap.** A count-controlled loop runs once per value in its range, and you can count the passes in advance.

## Practice

8 questions on this page, each with its working shown.

## Needs first

- [Selection with if, elif and else](https://lightmysky.com/learn/computing/selection-with-if-elif-and-else-mt_zylJ-p9g1g)

## Opens up

- [Condition-Controlled Loops](https://lightmysky.com/learn/computing/condition-controlled-loops-mt_LjxO2n3Fy6)
