SmallBASIC GuideThe language | Programming Tips | Commands | System | Graphics & Sound | Miscellaneous | File system | Mathematics | 2D Algebra | Strings | Console | Glossary |
Loops and expressions

FOR-like commands evaluate the 'destination' every time. Also, loops evaluate the exit-expression every time too.
FOR i=0 TO LEN(FILES("*.txt"))-1
    PRINT i
NEXT
In that example the 'destination' is the LEN(FILES("*.txt"))-1 For each value of i the destination will be evaluated. That is WRONG but it is supported by BASIC and many other languages. So, it is much better to be rewritten as
idest=LEN(FILES("*.txt"))-1
FOR i=0 TO idest
    PRINT i
NEXT
Of course, it is much faster too.


[Prev] [Next]