Quote:cls
do
print b;
b=b+.1
a=a+1
loop until a=70
.....
In addition to what others said, this code has another problem if using floats instead of integers. Consider the line:
loop until a=70
this line may never be true. When using floats in a conditional test, always test using, eg greater than rather than equals to avoid this problem. Better yet, avoid floats altogether, except when you need them. when doing integer divition, use the mod operator to keep track of the remainder. Never use a float as a counter. Never index an array with a float.
QB is pretty good about hiding conversions from you...for example if you:
pset(123.456, 89.012)
QB will not complain and simply convert the decimals to ints...whether it rounds or truncates the numbers...well...I don't know which it does off the top of my head, although it'd be easy to determine using pairs of pset(x,y) and point(x,y) statements.
Anyway...once you get used to *not* using floats, you find that you don't miss them one bit...and your programs will run faster.
The following tests the speed of int vs float. I get ratio of ~8. Anyone care to tell the value if ffix is used??
Code:
DEFINT I 'an integer number
DEFSNG F 'a floating point number
CLS
'counts using 16-bit integers
'cumbersome nested loops used to avoid 16-bit overflow
t = TIMER + 1
DO
FOR i1 = 1 TO 1000
FOR i2 = 1 TO 1000
FOR i3 = 1 TO 1000
NEXT i3
IF (TIMER > t) THEN EXIT DO
NEXT i2
NEXT i1
LOOP
countINT = (i1 * 1000000!) + (i2 * 1000!) + (i3 * 1!)
'counts using single precision floating point numbers
'cumbersome nested loops used to avoid introducing bias
t = TIMER + 1
DO
FOR f1 = 1 TO 1000
FOR f2 = 1 TO 1000
FOR f3 = 1 TO 1000
NEXT f3
IF (TIMER > t) THEN EXIT DO
NEXT f2
NEXT f1
LOOP
countFLOAT = (f1 * 1000000!) + (f2 * 1000!) + (f3 * 1!)
PRINT "after one sec ints were added"; countINT; "times"
PRINT "after one sec floats were added"; countFLOAT; "times"
PRINT "int to float speed ratio ="; countINT / countFLOAT