Exit Statement

Do...Loop, For...Next, ํ•จ์ˆ˜ ๋˜๋Š” ์„œ๋ธŒ๋ฃจํ‹ด์„ ์ข…๋ฃŒํ•ฉ๋‹ˆ๋‹ค.

๊ตฌ๋ฌธ:

๋งค๊ฐœ ๋ณ€์ˆ˜ ์ฐธ์กฐ

๋งค๊ฐœ ๋ณ€์ˆ˜:

Exit Do

Do...Loop ๋ฌธ ๋‚ด์—์„œ๋งŒ ์œ ํšจํ•˜๋ฉฐ ๋ฃจํ”„๋ฅผ ์ข…๋ฃŒํ•ฉ๋‹ˆ๋‹ค. Loop ๋ฌธ ๋’ค์— ์˜ค๋Š” ๋ฌธ์—์„œ ํ”„๋กœ๊ทธ๋žจ ์‹คํ–‰์ด ๊ณ„์†๋ฉ๋‹ˆ๋‹ค. Do...Loop ๋ฌธ์ด ์ค‘์ฒฉ๋œ ๊ฒฝ์šฐ ์ฝ˜ํŠธ๋กค์ด ๋‹ค์Œ ์ƒ์œ„ ์ˆ˜์ค€์˜ ๋ฃจํ”„๋กœ ์ด๋™ํ•ฉ๋‹ˆ๋‹ค.

Exit For

For...Next ๋ฃจํ”„ ๋‚ด์—์„œ๋งŒ ์œ ํšจํ•˜๋ฉฐ ๋ฃจํ”„๋ฅผ ์ข…๋ฃŒํ•ฉ๋‹ˆ๋‹ค. Next ๋ฌธ ๋‹ค์Œ์— ์˜ค๋Š” ์ฒซ ๋ฒˆ์งธ ๋ฌธ์—์„œ ํ”„๋กœ๊ทธ๋žจ์ด ์‹คํ–‰์ด ๊ณ„์†๋ฉ๋‹ˆ๋‹ค. ์ค‘์ฒฉ๋œ ๋ฌธ์—์„œ๋Š” ์ œ์–ด๊ฐ€ ๋‹ค์Œ ์ƒ์œ„ ์ˆ˜์ค€์˜ ๋ฃจํ”„๋กœ ์ด๋™ํ•ฉ๋‹ˆ๋‹ค.

Exit Function

Function ํ”„๋กœ์‹œ์ €๋ฅผ ์ฆ‰์‹œ ์ข…๋ฃŒํ•ฉ๋‹ˆ๋‹ค. Function ํ˜ธ์ถœ ๋’ค์— ์˜ค๋Š” ๋ฌธ์—์„œ ํ”„๋กœ๊ทธ๋žจ ์‹คํ–‰์ด ๊ณ„์†๋ฉ๋‹ˆ๋‹ค.

Exit Sub

์„œ๋ธŒ๋ฃจํ‹ด์„ ์ฆ‰์‹œ ์ข…๋ฃŒํ•ฉ๋‹ˆ๋‹ค. Sub ํ˜ธ์ถœ ๋’ค์— ์˜ค๋Š” ๋ฌธ์—์„œ ํ”„๋กœ๊ทธ๋žจ ์‹คํ–‰์ด ๊ณ„์†๋ฉ๋‹ˆ๋‹ค.

์ฐธ๊ณ  ์•„์ด์ฝ˜

Exit ๋ฌธ์€ ๊ตฌ์กฐ์˜ ๋์„ ์ง€์ •ํ•˜์ง€ ์•Š์œผ๋ฉฐ End ๋ฌธ๊ณผ ํ˜ผ๋™ํ•ด์„œ๋Š” ์•ˆ ๋ฉ๋‹ˆ๋‹ค.


์˜ˆ:

Sub ExampleExit

Dim sReturn As String

Dim sListArray(10) As String

Dim siStep As Single

    For siStep = 0 to 10 REM Fill array with test data

        sListArray(siStep) = chr(siStep + 65)

        MsgBox sListArray(siStep)

    Next siStep

    sReturn = LinSearch(sListArray(), "B")

    Print sReturn

End Sub

 

Function LinSearch( sList(), sItem As String ) As Integer

Dim iCount As Integer

REM LinSearch searches a TextArray:sList() for a TextEntry:

REM Returns the index of the entry or 0 ( Null)

    For iCount=1 To Ubound( sList() )

        If sList( iCount ) = sItem Then

            Exit for REM sItem found

        End If

    Next iCount

    If iCount = Ubound( sList() ) Then iCount = 0

    LinSearch = iCount

End Function