Skip to content · ⁨Pular para o conteúdo⁩

The loop that never ends · ⁨O loop que nunca termina⁩

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.

Português

O loop que nunca termina

Execute isso primeiro e veja o que acontece. A linha que torna count menor está lá — mas está fora do loop, então nunca roda.

No Python, a indentação é a estrutura: linhas indentadas sob while pertencem ao loop e se repetem; uma linha voltada para a margem esquerda vem depois do loop e roda apenas uma vez no final. Aqui o loop nunca reaches sua última linha, então sua condição permanece verdadeira para sempre. A página notará e parará por você, mas seu programa deve parar a si mesmo.

Log in or create account · ⁨Entrar ou criar conta⁩

IGCSE, A-Level & AP