Bounds test.
n = Bound(n, lo, hi)
n, lo, hi:iexp
The Bound(n, lo, hi) function tests whether the parameter n lies within the bounds of lo and hi (inclusive). This means that when n < lo or n > hi an error message is reported. Otherwise n is returned unchanged.
OpenW # 1
Local i%, q%
Dim a%(49)
For i% = 1 To 20
q% = Rand(49) + 1
While a%(q%)
q%++
Wend
Inc a%(q%)
Next i%
CloseW # 1
This programs selects 20 random numbers between 1 and 49 without repetition. The frequency of the number (zero or once) is noted in array a%().If Rand() returns a number for the second time the next higher number is taken instead. After many test runs an error (array index too big) appears several times.
To locate this error the line q%++ can, for example, be changed to
q% = Bound(q% + 1, 1, 49)
This will cause an error (Bound Error) on the line where q% is modified (q%++). In this way the place where the range is exceeded is easier to find.
The Bound() function serves to find program errors by early discovery of any range violations.
{Created by Sjouke Hamstra; Last updated: 24/09/2014 by James Gaite}