Iteration: WHILE and REPEAT · 반복: WHILE 및 REPEAT
This page needs a recent browser (with SharedArrayBuffer support). Please update Chrome, Edge, Firefox or Safari to the latest version. · 이 페이지는 최신 브라우저(SharedArrayBuffer 지원)가 필요합니다. Chrome, Edge, Firefox 또는 Safari를 최신 버전으로 업데이트해 주세요.
English
WHILE tests first
- A pre-condition loop tests the condition, then maybe runs the body.
- If the condition is already
FALSE, the body never runs. - The block ends at
ENDWHILE.
한국어
WHILE 먼저 테스트
- 전제 조건 루프는 조건을 먼저 테스트한 후, 필요에 따라 본문을 실행합니다.
- 조건이 이미
FALSE인 경우, 본문은 절대 실행되지 않습니다. - 블록은
ENDWHILE에서 끝납니다.
DECLARE N : INTEGER
N ← 3
WHILE N > 0
OUTPUT N
N ← N - 1
ENDWHILE
English
REPEAT runs, then tests
- A post-condition loop runs the body, then tests.
- The body runs at least once.
- The loop stops when the condition becomes
TRUE.
한국어
REPEAT는 실행 후 테스트함
- 후위 조건 루프는 먼저 본문을 실행한 후 조건을 테스트합니다.
- 본문은 최소 한 번은 실행됩니다.
- 조건이
TRUE이 되면 루프가 멈춥니다.
DECLARE N : INTEGER
N ← 0
REPEAT
N ← N + 1
OUTPUT N
UNTIL N = 3
English
Watch out
WHILEstops onFALSE.REPEATstops onTRUE. They are opposite tests.- Something inside a
WHILEmust change the condition, or the loop never ends.
한국어
주의사항
WHILE은FALSE에서 멈춥니다.REPEAT은TRUE에서 멈춥니다. 이들은 반대되는 테스트입니다.WHILE내부의 무언가가 조건을 변경하지 않으면 루프가 끝나지 않습니다.
English
Common mistakes
ENDWHILEcloses aWHILE.UNTILcloses aREPEAT.- A
REPEATthat should stop at 3 must updateNbefore the test.
한국어
흔한 실수
ENDWHILE는WHILE을 닫습니다.UNTIL은REPEAT을 닫습니다.- 3에서 멈춰야 할
REPEAT은 테스트 전에N을 업데이트해야 합니다.
English
Now you try
- Write one
WHILEand oneREPEAT.
한국어
이제 직접 해보기
- 하나의
WHILE와 하나의REPEAT을 작성하십시오.
Set N to 3. While N is greater than 0, output N and then subtract 1. · N을 3로 설정하십시오. N이 0보다 크면 N을 출력하고 이후 1을 빼십시오.
Click Run to see the output here. · 출력을 보려면 '실행'을 클릭하세요.
Use REPEAT … UNTIL to output 1, 2 and 3. · REPEAT … UNTIL을 사용하여 1, 2, 3을 출력하십시오.
Click Run to see the output here. · 출력을 보려면 '실행'을 클릭하세요.