|
|
(5 intermediate revisions by 3 users not shown) |
Line 1: |
Line 1: |
| EXIT Do
| | Exit Do |
|
| |
|
| EXIT For
| | Exit For |
|
| |
|
| EXIT Function
| | Exit Function |
|
| |
|
| EXIT Sub
| | 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.
| | 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> | | <tabber> |
| REM EXIT Example
| | JavaScript= |
| 'EXIT terminates loops and procedures | | <syntaxhighlight lang="JavaScript"> |
| | // Exit Example |
| | /* Break terminates loops */ |
| | /* Return terminates functions */ |
| | |
| | var i; |
| | for(i = 1; i <= 10; ++i) { |
| | if(i > 1) { |
| | break; |
| | } |
| | NSB.Print("Attempting to do nothing"); |
| | DoNothing(); |
| | } |
| | NSB.Print(("Done") + "<br>"); |
| | function DoNothing() { |
| | return; |
| | NSB.Print("This statement is never executed"); |
| | } |
| | </syntaxhighlight> |
| | |-| |
| | BASIC= |
| | <syntaxhighlight lang="vb.net"> |
| | 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 | | Exit For |
| END If | | End If |
| PRINT "Attempting to do nothing" | | Print "Attempting to do nothing" |
| DoNothing | | DoNothing |
| Next | | Next |
| PRINT "Done"
| | Print "Done" |
| Sub DoNothing | | Sub DoNothing |
| EXIT Sub | | Exit Sub |
| PRINT "This statement is never executed" | | Print "This statement is never executed" |
| End Sub | | End Sub |
| </pre> | | </syntaxhighlight> |
| | </tabber> |
|
| |
|
| == Output == | | == Output == |
Line 40: |
Line 64: |
| == Related Items == | | == Related Items == |
|
| |
|
| [[for...next|FOR...NEXT]], [[do...loop|DO...LOOP]], [[function|FUNCTION]], [[property|PROPERTY]], [[sub|SUB]] | | [[for...next|For...Next]], [[do...loop|Do...Loop]], [[function|Function]], [[properties and methods|Properties]], [[sub|Sub]] |
|
| |
|
| [[Category:Language Reference]] | | [[Category:Language Reference]] |
| | |
| | [[Category:Statements - Flow of control]] |
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
// Exit Example
/* Break terminates loops */
/* Return terminates functions */
var i;
for(i = 1; i <= 10; ++i) {
if(i > 1) {
break;
}
NSB.Print("Attempting to do nothing");
DoNothing();
}
NSB.Print(("Done") + "<br>");
function DoNothing() {
return;
NSB.Print("This statement is never executed");
}
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
Related Items
For...Next, Do...Loop, Function, Properties, Sub