Skip to content · ⁨Passer au contenu⁩

The loop that never ends · ⁨La boucle qui ne finit jamais⁩

English

The loop that never ends

Run this first and watch what happens. The line that makes count smaller is there — but it is outside the loop, so it never runs.

In Python the indentation is the structure: lines indented under while belong to the loop and repeat, a line back at the left margin comes after the loop and runs once at the end. Here the loop never reaches its last line, so its question stays true for ever. The page will notice and stop it for you, but your program should stop itself.

Français

La boucle qui ne finit jamais

Exécutez ceci d'abord et regardez ce qui se passe. La ligne qui rend count plus petite est là — mais elle est en dehors de la boucle, donc elle ne s'exécute jamais.

En Python, l'indentation est la structure : les lignes indentées sous while appartiennent à la boucle et se répètent, une ligne retournée à la marge de gauche arrive après la boucle et s'exécute une fois à la fin. Ici, la boucle n'atteint jamais sa dernière ligne, donc sa question reste vraie pour toujours. La page remarquera et l'arrêtera pour vous, mais votre programme devrait s'arrêter lui-même.

Log in or create account · ⁨Se connecter ou créer un compte⁩

IGCSE, A-Level & AP