Exit Command

Purpose

Exits a loop.

Syntax

Exit [Do | For]

Description

The Exit command makes it possible to exit any loop (For...Next, While...Wend, Repeat...Until and Do...Loop). In contrast to the GoTo command, a loop is terminated in an "orderly" fashion by using Exit.

In other words, Exit always jumps to the first programming statement after the last line of the loop, while GoTo can jump anywhere within a Procedure or Function.

Exit Do and Exit For help to distinguish between the loops and helps in preventing errors.

Example

OpenW # 1

Dim e% = 1

Dim i% = 1

Do

e% *= i%

Print Str$(i%) + "! = "; Str$(e%, 5)

If e% > 32000 Then Exit Do

i% ++

Loop

Calculates the factorial and stores the result in the variable e%. The calculation is terminated if the result exceeds 32000.

Remarks

The If condition Then Exit Do (or Loop) command common to other dialects of BASIC can also be used.

See Also

Goto, Exit If, Exit Sub

{Created by Sjouke Hamstra; Last updated: 05/10/2014 by James Gaite}