The loop that never ends · 끝나지 않는 루프
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.
영원히 끝나지 않는 루프
먼저 이 코드를 실행해 보십시오. count를 작게 만드는 줄은 존재하지만, 루프 바깥에 있으므로 실행되지 않습니다.
Python에서 들여쓰기는 코드 구조 자체입니다: while 아래에 들여쓰기된 줄은 루프에 속하여 반복되고, 왼쪽 여백으로 돌아온 줄은 루프 이후에 위치하여 마지막에 한 번만 실행됩니다. 여기서 루프는 마지막 줄에 도달하지 못하므로 질문은 항상 참이 됩니다. 페이지가 이를 감지하여 중지해 주지만, 사용자 프로그램 스스로 정지해야 합니다.
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. · 먼저 실행해 보고 결과를 확인하십시오. count을 작게 만드는 줄은 있지만 루프 외부에 있어 실행되지 않습니다. 이를 루프 내부로 이동시켜 프로그램이 5, 4, 3, 2, 1을 출력하고 멈추도록 하십시오.
Click Run to see the output here. · 출력을 보려면 '실행'을 클릭하세요.