The loop that never ends · El bucle 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.
El bucle que nunca termina
Ejecuta esto primero y observa qué sucede. La línea que hace que count disminuya está presente, pero se encuentra fuera del bucle, por lo que nunca se ejecuta.
En Python, la sangría es la estructura: las líneas sangradas bajo while pertenecen al bucle y se repiten; una línea en el margen izquierdo sale del bucle y se ejecuta una sola vez al final. Aquí, el bucle nunca llega a su última línea, por lo que su condición permanece verdadera para siempre. La página lo notará y lo detendrá por ti, pero tu programa debería detenerse solo.
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. · Ejecuta esto primero y observa qué sucede. La línea que hace que count sea más pequeña está ahí, pero se encuentra fuera del bucle, por lo que nunca se ejecuta. Muévela adentro para que el programa imprima 5, 4, 3, 2, 1 y se detenga.
Click Run to see the output here. · Haz clic en Ejecutar para ver la salida aquí.