Choose loops and validate input
Match the loop to the requirement
Use FOR for a known number of accepted items, WHILE when zero iterations are possible, and REPEAT when reading at least once is required. A sentinel marks the end of input; it is not ordinary data.

Separate attempts from accepted items
To read three valid scores: the outer loop counts accepted scores; the inner REPEAT handles attempts for one score. Add to Total only after validation succeeds.
DECLARE Attempt : ARRAY[1:6] OF INTEGER
DECLARE Position, Score, Total, I : INTEGER
Attempt[1] ← 25
Attempt[2] ← 7
Attempt[3] ← -1
Attempt[4] ← 20
Attempt[5] ← 0
Attempt[6] ← 9
Position ← 1
Total ← 0
FOR I ← 1 TO 3
REPEAT
Score ← Attempt[Position]
Position ← Position + 1
UNTIL Score >= 0 AND Score <= 20
Total ← Total + Score
NEXT I
OUTPUT Total
OUTPUT Position - 1, " attempts"
The array stands in for the keyboard. 25 and -1 are rejected, so 7, 20 and 0 are accepted: the output is 27, then 5 attempts. Replace Attempt[Position] with INPUT Score and nothing else changes.

Common mistakes
- Adding to
Totalinside theREPEAT. Every invalid attempt is then counted. Add only afterUNTIL. - Writing the invalid condition after
UNTIL:UNTIL Score < 0 OR Score > 20stops at the first bad value and accepts it. - Letting a rejected attempt advance the
FORcounter.Icounts accepted scores, so an extra attempt must stay inside the inner loop. - Adding the sentinel to the total. Test for the sentinel before the value is used.
Test the decisions
For the inclusive interval 0 to 20 use -1, 0, 20 and 21 as boundary tests. An invalid attempt must neither increase the accepted-item count nor contribute to the total. Explain why UNTIL uses the valid condition, rather than the invalid condition.
난이도 3/5 · 200코인 + 오늘 첫 완료 시 작은 보너스 추가
A system must read at least one value and repeat until it is valid. Which loop most directly expresses this: FOR, WHILE or REPEAT?
난이도 3/5 · 200코인 + 오늘 첫 완료 시 작은 보너스 추가
Read integers until one is 1 to 9 inclusive. Output only the accepted value.
출력을 보려면 '실행'을 클릭하세요.
난이도 3/5 · 200코인 + 오늘 첫 완료 시 작은 보너스 추가
Read NumberOfScores (1 to 5). For EACH score, read repeatedly until it is 0 to 20 inclusive. Output the total of the NumberOfScores accepted scores. Do not count invalid attempts.
출력을 보려면 '실행'을 클릭하세요.
Explain your choice of data structure and loop. Identify one boundary case and predict its result. For a subroutine, explain what is returned or changed in the caller.
이 브라우저의 이번 세션에 저장되었습니다. 교사나 본인이 직접 검토하십시오; 이 설명은 자동으로 채점되지 않습니다.
해당 설명을 다음 기준에 따라 검토하십시오.
- My types and data structure match the data and the question.
- I justified the loop and checked its first and last iterations.
- Initial values and rejected operations preserve the intended state.
- My test includes input, purpose and expected result.
- I distinguished returning a value from printing and changing caller state.