SecondBASIC Documentation v3

Home / Command Reference / For...Next

For...Next

Description: Creates a loop that will repeat for the range specified, or the Exit For command is encountered.

Syntax:

For <CounterVariable> = <StartValue> To <EndValue> [Step <StepValue>]
    ' code to execute
Next

Part Description
<CounterVariable> Required. This can either be an integer or long variable only. This variable will increment (or decrement) on each iteration of the loop.
<StartValue> Required. The <StartValue> can be either an integer or long variable, or a constant. This is the starting value that the <CounterVariable> will start at.
<EndValue> Required. This is the ending value for the loop. You can use a constant, integer or long variable, or even an expression. This value can be lower than the <StartValue>, but will require a negative <StepValue> (see below).
<StepValue> Optional. The <StepValue> tells the loop how to increment each iteration. The default is Step 1. You can use an integer or long variable, or a constant. If your <EndValue> is smaller than your <StartValue>, you will need a negative Step value.

Example:

    For x = 0 To 10 Step 2
        Print x
    Next