Exit: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
Exit Do | |||
Exit For | |||
Exit Function | |||
Exit Sub | |||
== Description == | == Description == | ||
Exit terminates the execution of a block of code in a Do...Loop, For...Next, For Each...Next, Function, or Sub. When used to exit a loop, either Do...Loop, For...Next, or For Each...Next, execution continues with the first statement after the loop; if the loop is nested inside another loop, control is transferred to the loop outside the loop where the Exit is encountered. When used to exit a Function or Sub procedure, execution continues with the first statement after the statement which called the procedure. | |||
== Example == | == Example == | ||
<pre> | <pre> | ||
REM | REM Exit Example | ||
' | 'Exit terminates loops and procedures | ||
Dim i | Dim i | ||
For i = 1 to 10 | For i = 1 to 10 | ||
If i > 1 Then | If i > 1 Then | ||
Exit For | |||
End If | |||
PRINT "Attempting to do nothing" | PRINT "Attempting to do nothing" | ||
DoNothing | DoNothing | ||
Line 26: | Line 26: | ||
PRINT "Done" | PRINT "Done" | ||
Sub DoNothing | Sub DoNothing | ||
Exit Sub | |||
PRINT "This statement is never executed" | PRINT "This statement is never executed" | ||
End Sub | End Sub |
Revision as of 21:21, 8 August 2012
Exit Do
Exit For
Exit Function
Exit Sub
Description
Exit terminates the execution of a block of code in a Do...Loop, For...Next, For Each...Next, Function, or Sub. When used to exit a loop, either Do...Loop, For...Next, or For Each...Next, execution continues with the first statement after the loop; if the loop is nested inside another loop, control is transferred to the loop outside the loop where the Exit is encountered. When used to exit a Function or Sub procedure, execution continues with the first statement after the statement which called the procedure.
Example
REM Exit Example 'Exit terminates loops and procedures Dim i For i = 1 to 10 If i > 1 Then Exit For End If PRINT "Attempting to do nothing" DoNothing Next PRINT "Done" Sub DoNothing Exit Sub PRINT "This statement is never executed" End Sub
Output
Atempting to do nothing Done