$For directive

Purpose

Disables overflow checking for For...Next statements

Syntax

$ForFast
$ForNoOver[flow[Check]]
$ForNoCheck[Over[flow]]

$ForSlow
$ForOver[flow[Check]]
$ForCheck[Over[flow]]

Description

$ForFast, or any one of the $ForNo.. variants, disables overflow checking of the count variable within a For...Next loop while $ForSlow, or any one of the $For.. variants, enables it again; the default state is enabled.

Overflow checking disabling is only possible with integer count variables. The performance gain is about 30% for an empty loop.

Example

Dim a$, i%, t As Double

$ForFast    ' Disable overflow checking

t = Timer

For i% = 0 To 1000000 : a$ = Str(i) : Next i%

Print "ForFast: "; Timer - t

$ForSlow    ' Enable overflow checking again

t = Timer

For i% = 0 To 1000000 : a$ = Str(i) : Next i%

Print "ForSlow: "; Timer - t

Remarks

For...Next loops until _maxInt are only possible with overflow check enabled. The following example would normally loop 101 times before the count variable i% will overflow (_maxInt to _minInt, 2147483647 to -2147483648, 0x7fffffff to 0x80000000). Normally, the loop is ended, however with $ForFast no overflow check is performed and results in an infinite loop.

Local i%, j%

j% = _maxInt

$ForFast

For i% = j% - 100 To j%    // Loop using $ForFast

Print i

Next

See Also

$AutoPost, $ArrayChk, For...Next, $Obj, $Step

{Created by Sjouke Hamstra; Last updated: 17/09/2014 by James Gaite}