Skip to content · ⁨본문 바로가기⁩

The loop that never ends · ⁨끝나지 않는 루프⁩

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.

한국어

영원히 끝나지 않는 루프

먼저 이 코드를 실행해 보십시오. count를 작게 만드는 줄은 존재하지만, 루프 바깥에 있으므로 실행되지 않습니다.

Python에서 들여쓰기는 코드 구조 자체입니다: while 아래에 들여쓰기된 줄은 루프에 속하여 반복되고, 왼쪽 여백으로 돌아온 줄은 루프 이후에 위치하여 마지막에 한 번만 실행됩니다. 여기서 루프는 마지막 줄에 도달하지 못하므로 질문은 항상 참이 됩니다. 페이지가 이를 감지하여 중지해 주지만, 사용자 프로그램 스스로 정지해야 합니다.

Log in or create account · ⁨로그인 또는 계정 만들기⁩

IGCSE, A-Level & AP