Friday, October 12, 2012

Use of FOR...NEXT

One way to execute a repetition of statements in BASIC is to use a FOR...NEXT loop.

The correct syntax is

FOR lcv = sv TO ev STEP incr
     ' BASIC code statements here
NEXT lcv

wherelcv = loop control variable
sv = start value
ev = end value
incr = increment to step
       defaults to 1 if not specified explicitly


Suppose that you wanted to print out a series of numbers in a countdown fashion, like so

You could do that with this code:


Notice how the increment is actually a negative number.

Now, isn't that cool?