API Basic Do ko - LIHACHTETAN/ClassicUO-BadNewbie-BasicIDE GitHub Wiki
Do / Loop / While / Until / Repeat
ClassicUO โข Basic
Do๋ ๋ณธ๋ฌธ ์ ์ด๋ ํ์ ์กฐ๊ฑด์ ๊ฒ์ฌํฉ๋๋ค. While๋ ์ฐธ์ธ ๋์, Until์ ์ฐธ์ด ๋ ๋๊น์ง ๋ฐ๋ณตํฉ๋๋ค. Repeat โฆ Until์ ๋ณธ๋ฌธ ๋ค์ ๊ฒ์ฌํ๋ ์ง์๋๋ ๊ธฐ์กด ํ์์ ๋๋ค.
์ ํํ ๊ตฌ๋ฌธ
Do While condition
statements
Loop
Do Until condition
statements
Loop
Do
statements
Loop While condition
Do
statements
Loop Until condition
Do
statements
Loop
Repeat
statements
Until condition
Continue Do
Exit Do
Break
๋งค๊ฐ๋ณ์
condition / While / Untilโ ์ซ์ Boolean ์ 0/False ๋๋ 1/True์ ๋๋ค. While๋ ์ฐธ์ด๋ฉด ๊ณ์ํ๊ณ Until์ ์ฐธ์ด๋ฉด ๋๋ ๋๋ค. ๋งค ๊ฒ์ฌ๋ง๋ค ๋ค์ ํ๊ฐํ๋ฉฐ ํ ์คํธ๋ฅผ Boolean์ผ๋ก ํด์ํ์ง ์์ต๋๋ค.position / Repeatโ Do ๋ค ์กฐ๊ฑด์ ์ฒซ ์คํ์ ์๋ตํ ์ ์์ต๋๋ค. Loop ๋ค๋ Repeat์ Until์ ์ต์ ํ ๋ฒ ์คํํ ๋ค ๊ฒ์ฌํฉ๋๋ค. ์กฐ๊ฑด ์์น๋ ํ๋๋ง ํ์ฉํฉ๋๋ค. ๋ฌด์กฐ๊ฑด Do โฆ Loop์๋ ๋ช ์์ ์ข ๋ฃ๊ฐ ํ์ํฉ๋๋ค.statements / exitโ ๋ณธ๋ฌธ์ ๋๋ค. Continue Do๋ ๋ค์ ์กฐ๊ฑด ๊ฒ์ฌ๋ก ์ด๋ํ๊ณ Exit Do๋ ๊ฐ์ฅ ๊ฐ๊น์ด Do๋ Repeat๋ฅผ ๋๋ ๋๋ค. Break๋ ์ข ๋ฅ์ ๋ฌด๊ดํ๊ฒ ๊ฐ์ฅ ๊ฐ๊น์ด ๋ฐ๋ณต๋ฌธ์ ์ข ๋ฃํฉ๋๋ค. RETURN์ ํ๋ก์์ /ํจ์ ์ ์ฒด๋ฅผ ๋๋ ๋๋ค.
๋ฐํ๊ฐ
Do, Loop, Repeat, Until, Exit Do์๋ ๋ฐํ๊ฐ์ด ์์ต๋๋ค. ์์ ๋ Main์์ Integer 1,33,83์ ๋ช ์์ ์ผ๋ก ๋ฐํํ๋ฉฐ ์ด๋ ๊ฒฐํฉ๋ ์นด์ดํฐ ๊ฐ์ด์ง ๋ช ๋ น์ Boolean ๊ฒฐ๊ณผ๊ฐ ์๋๋๋ค.
๋์
- ์ค๋น ๋จ๊ณ์์ ๋ธ๋ก๊ณผ ์ด๋์ ๊ฒ์ฌํฉ๋๋ค. ๊ฐ์ Do์ ์ฒ์๊ณผ ๋ ๋ชจ๋์ ์กฐ๊ฑด์ ์ง์ ํ๋ฉด SC020์ ๋๋ค. ์์ง์ ์ ํํ ์์น์์ ํ๊ฐํ๊ณ While/Until ๊ท์น์ผ๋ก ๋ฐ๋ณตํฉ๋๋ค.
- ํ์กฐ๊ฑด์ Continue Do๋ ๋ ์กฐ๊ฑด์ ๋ฐ๋์ ๊ฒ์ฌํ๋ฉฐ ์ ์กฐ๊ฑด์ด๋ฉด ํค๋๋ก ๋์๊ฐ๋๋ค. Try๋ฅผ ๋ ๋๋ ์ด๋ ์ ์ Finally๊ฐ ์ ํํ ํ ๋ฒ ์คํ๋ฉ๋๋ค.
- Repeat๋ ๋จผ์ ์คํํ๋ฏ๋ก ๋น ๋ฐฐ์ด์ ์ง์ ์ ์ ์ฒ๋ฆฌํ์ธ์. ์๋ฌต์ ์๊ฐ ์ ํ์ ์์ต๋๋ค. ๊ฒ์ ๋๊ธฐ์๋ Wait์ ๊ธฐํ์ ์ฌ์ฉํ๋ฉฐ ์ผ์ ์ค์งยท์ ์ง ๊ฒ์ฌ๋ ์ ์ง๋ฉ๋๋ค.
์์
1. ์ ํ ๊ฒ์ฌ ์ฐจ์ด
# ready=True๋ ์ด๋ฏธ Until์ ๋ง์กฑํฉ๋๋ค. Do Until ready๋ 0๋ฒ ์คํํ์ฌ before=0์
๋๋ค. ๋ ๋ฒ์งธ ๋ฐ๋ณต์ ์ฆ๊ฐ ํ ๊ฒ์ฌํ๋ฏ๋ก after=1์
๋๋ค. Main์ before*10+after=1์ ๋ฐํํฉ๋๋ค.
Option Explicit On
Sub Main()
Var ready = True
Var before = 0
Var after = 0
Do Until ready
before += 1
Loop
Do
after += 1
Loop Until ready
Return before * 10 + after
End Sub
๋งค๊ฐ๋ณ์ ๋ฐ ์คํ ์ค๋ช :
ready=True๋ ์ด๋ฏธ Until์ ๋ง์กฑํฉ๋๋ค. Do Until ready๋ 0๋ฒ ์คํํ์ฌ before=0์ ๋๋ค. ๋ ๋ฒ์งธ ๋ฐ๋ณต์ ์ฆ๊ฐ ํ ๊ฒ์ฌํ๋ฏ๋ก after=1์ ๋๋ค. Main์ before*10+after=1์ ๋ฐํํฉ๋๋ค.
2. ์ ํ๋ ์๋์ ์ ๋ฆฌ
# attempts๋ 0์์ ์์ํด ๋งค๋ฒ ๋์ด๋ฉ๋๋ค. ์ฒซ ๋ Continue Do๋ Finally๋ฅผ ์คํํ ๋ค attempts<4๋ฅผ ๊ฒ์ฌํฉ๋๋ค. ์ธ ๋ฒ์งธ Exit Do๋ Finally๋ฅผ ์คํํฉ๋๋ค. attempts=3, cleanup=3์ด๋ฏ๋ก 33์
๋๋ค. ์ค์ ๋คํธ์ํฌ ์ฌ์๋๊ฐ ์๋ ๋ก์ปฌ ์๋ฎฌ๋ ์ด์
์
๋๋ค.
Option Explicit On
Sub Main()
Var attempts = 0
Var cleanup = 0
Do
Try
attempts += 1
If attempts < 3 Then
Continue Do
End If
Exit Do
Finally
cleanup += 1
End Try
Loop While attempts < 4
Return attempts * 10 + cleanup
End Sub
๋งค๊ฐ๋ณ์ ๋ฐ ์คํ ์ค๋ช :
attempts๋ 0์์ ์์ํด ๋งค๋ฒ ๋์ด๋ฉ๋๋ค. ์ฒซ ๋ Continue Do๋ Finally๋ฅผ ์คํํ ๋ค attempts<4๋ฅผ ๊ฒ์ฌํฉ๋๋ค. ์ธ ๋ฒ์งธ Exit Do๋ Finally๋ฅผ ์คํํฉ๋๋ค. attempts=3, cleanup=3์ด๋ฏ๋ก 33์ ๋๋ค. ์ค์ ๋คํธ์ํฌ ์ฌ์๋๊ฐ ์๋ ๋ก์ปฌ ์๋ฎฌ๋ ์ด์ ์ ๋๋ค.
3. ์ข ๋ฃ ํ์์ ์ฝ๋ ๊ธฐ์กด ๋ฐ๋ณต๋ฌธ
# values=[3,5,0]์ ๋น์ด ์์ง ์์ต๋๋ค. Repeat๋ ์
์ ์ฝ๊ณ index๋ฅผ ๋๋ ค ํฉ์ฐํฉ๋๋ค. Until์ 0์ด๋ ๋ฐฐ์ด ๋์์ ๋ฉ์ถ๋ฉฐ 0์ ์ฐพ์ผ๋ฉด OrElse๊ฐ ๋ ๋ฒ์งธ ๊ฒ์ฌ๋ฅผ ์๋ตํฉ๋๋ค. total=8, index=3์ผ๋ก 83์ ๋ฐํํฉ๋๋ค.
Option Explicit On
Sub Main()
Dim values[2]
values[0] = 3
values[1] = 5
values[2] = 0
Var index = 0
Var value = 0
Var total = 0
Repeat
value = values[index]
index += 1
total += value
Until (value = 0) OrElse (index >= GetArrayLength(values))
Return total * 10 + index
End Sub
๋งค๊ฐ๋ณ์ ๋ฐ ์คํ ์ค๋ช :
values=[3,5,0]์ ๋น์ด ์์ง ์์ต๋๋ค. Repeat๋ ์ ์ ์ฝ๊ณ index๋ฅผ ๋๋ ค ํฉ์ฐํฉ๋๋ค. Until์ 0์ด๋ ๋ฐฐ์ด ๋์์ ๋ฉ์ถ๋ฉฐ 0์ ์ฐพ์ผ๋ฉด OrElse๊ฐ ๋ ๋ฒ์งธ ๊ฒ์ฌ๋ฅผ ์๋ตํฉ๋๋ค. total=8, index=3์ผ๋ก 83์ ๋ฐํํฉ๋๋ค.