Skip to content

EXIT


Control flow statement to exit a compound statement block

Syntax

vb
Exit {Do | For | While | Select }
Exit {Sub | Function | Operator | Constructor | Destructor | Property }

Exit {Do [, Do [ , ...] ] |

For [, For [ , ...] ] |
While [, While, [...] ] |
Select [, Select [ , ...] ] }

Description

Leaves a code block such as a Sub, Function, Operator, Constructor, Destructor, Property, Do...Loop, For...Next, While...Wend, or a Select Case block. The execution skips the rest of the block and goes to the line after its end.

Where there are multiple Do / For / While / Select blocks nested, it will skip to the end of the innermost block of that type. You can skip to the end of multiple blocks of that type by giving the word multiple times, separated by commas.

For example: Exit While, While

Examples

start GeSHi

vb
'e.g. the print command will not be seen

Do
    Exit Do ' Exit the Do...Loop and continues to run the code after Loop
    Print "I will never be shown"
Loop

end GeSHi

start GeSHi

vb
Dim As Integer i, j
For i = 1 To 10
   
    For j = 1 To 10
       
        Exit For, For
       
    Next j
   
    Print "I will never be shown"
   
Next i

end GeSHi

Differences from QB

  • EXIT OPERATOR, EXIT CONSTRUCTOR, EXIT DESTRUCTOR, EXIT PROPERTY, EXIT WHILE and EXIT SELECT are new to FreeBASIC.

See also

  • Sub
  • Function
  • Do...Loop
  • For...Next
  • While...Wend
  • Continue

Back to DocToc

Translated from FreeBASIC official docs. Contact us for removal if infringed.
FreeBASIC is an open-source project, not affiliated with Microsoft