Nested decisions · 중첩된 결정
One mark, three outcomes
- A mark of 80 or more is a distinction, 50 or more is a pass, and anything lower is a fail.
- One
IFhas two paths. The second decision goes inside theELSE, as its ownIF. - Each
IFhas its ownENDIF. Indent the inner one so you can see whichELSEit belongs to.
한 점, 세 가지 결과
- 80점 이상은 우등(distinction), 50점 이상은 합격(pass), 그 이하의 모든 점수는 불합격(fail)입니다.
- 하나의 **
IF**는 두 가지 경로를 가집니다. 두 번째 결정은ELSE내부에 위치하며, 그 자체로 하나의 **IF**입니다. - 각 **
IF**는 고유한 **ENDIF**을 가집니다. 안쪽의 것을 들여쓰기하여 어떤 **ELSE**에 속하는지 알 수 있게 하십시오.
DECLARE Mark : INTEGER
Mark ← 72
IF Mark >= 80
THEN
OUTPUT "Distinction"
ELSE
IF Mark >= 50
THEN
OUTPUT "Pass"
ELSE
OUTPUT "Fail"
ENDIF
ENDIF
Count the marks that count
- A validation tally walks the list and adds 1 only when the value is in range.
- The range test is the
ANDfrom the previous lesson, inside the loop.
유효한 점수만 세세요
- 검증 카운터는 목록을 순회하며 값이 범위 내에 있을 때만 1을 더합니다.
- 범위 테스트는 이전 수업의 **
AND**이며, 루프 내부에 있습니다.
DECLARE Mark : ARRAY[1:4] OF INTEGER
DECLARE I, Count : INTEGER
Mark[1] ← 80
Mark[2] ← -1
Mark[3] ← 100
Mark[4] ← 40
Count ← 0
FOR I ← 1 TO 4
IF Mark[I] >= 0 AND Mark[I] <= 100
THEN
Count ← Count + 1
ENDIF
NEXT I
OUTPUT Count // → 3
Watch out
- The inner
IFstarts on the line afterELSE. It is not written on theELSEline. - Close the inner
ENDIFbefore the outer one. The lastENDIFbelongs to the firstIF.
주의사항
- 안쪽의 **
IF**는ELSE바로 다음 줄에서 시작됩니다.ELSE줄에 쓰이지 않습니다. - 바깥쪽보다 안쪽의 **
ENDIF**를 먼저 닫으십시오. 마지막 **ENDIF**은 첫 번째 **IF**에 속합니다.
Common mistakes
- An
ENDIFin the wrong place closes the outer test and leaves the inner one open. - A mark of exactly 50 is a pass, and exactly 80 is a distinction. The tests use
>=.
흔한 실수
- 잘못된 위치에 있는 **
ENDIF**는 바깥쪽 테스트를 닫고 안쪽 테스트를 열게 만듭니다. - 정확히 50점은 합격이고, 정확히 80점은 우등입니다. 테스트에는 **
>=**를 사용합니다.
Now you try
- The first two tasks are nested decisions. The third counts with
AND. - Press Check answer to test it.
이제 직접 해보기
- 첫 두 개의 작업은 중첩된 결정(nested decisions)입니다. 세 번째 작업은 **
AND**로 세어집니다. - 답안 확인을 눌러 테스트해 보십시오.
Read an INTEGER Mark. Output Distinction for 80 or more, otherwise Pass for 50 or more, otherwise Fail. Nest the second IF under ELSE. · INTEGER Mark을 읽습니다. 80 이상이면 Distinction를 출력하고, 그렇지 않으면 50 이상이면 Pass을 출력하며, 그렇지 않으면 Fail을 출력합니다. 두 번째 IF을 ELSE 아래에 중첩합니다.
Click Run to see the output here. · 출력을 보려면 '실행'을 클릭하세요.
Same three outcomes as the previous task. This input should take the inner ELSE. · 이전 작업과 동일한 세 가지 결과입니다. 이 입력은 내부 ELSE을 가져와야 합니다.
Click Run to see the output here. · 출력을 보려면 '실행'을 클릭하세요.
The array Mark holds 80, -1, 100, 40. Count how many values are from 0 to 100 inclusive and output the count (it is 3). · 배열 Mark에는 ⟨80, -1, 100, 40⟩가 들어 있습니다. 0부터 100까지(포함)인 값이 몇 개인지 세어 그 개수(3)를 출력합니다.
Click Run to see the output here. · 출력을 보려면 '실행'을 클릭하세요.