Serves to terminate a loop when the condition following Exit...If is logically "true".
Exit [Do | For] If condition
Condition:any numerical, logical or string condition
The Exit If command makes it possible to test and exit any loop for a condition other than the one specified in the loop itself (see 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 If.
In other words, Exit If always jumps to the first programming statement after the last line of the loop, while GoTo can jump anywhere within a Procedure or Function.
OpenW # 1
Dim e% = 1
Dim i% = 1
Do
e% *= i%
Print Str$(i%) + "! = "; Str$(e%, 5)
Exit If e% > 32000
i% ++
Loop
calculates the factorial and stores the result in the variable e%. The calculation is terminated if the result exceeds 32000.
The If condition Then Exit Do (or Loop) command common to other dialects of BASIC can also be used.
{Created by Sjouke Hamstra; Last updated: 05/10/2014 by James Gaite}