The loop that never ends · O loop que nunca termina
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.
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.
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. Move it inside so the program prints 5, 4, 3, 2, 1 and stops. · Execute isso primeiro e veja o que acontece. A linha que torna count menor está lá — mas ela está fora do loop, então nunca roda. Mova-a para dentro para que o programa imprima 5, 4, 3, 2, 1 e pare.
Click Run to see the output here. · Clique em Executar para ver a saída aqui.