[<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
FOR                      Begin Definition of FOR/NEXT Loop

 FOR counter = start TO end [STEP increment]
 .
 . [statements]
 .
 [EXIT FOR]
 NEXT [counter [,counter...]]

    Begins the definition of a FOR/NEXT loop.

     counter    A numeric variable to be used as the loop counter. All
                numeric types are allowed, but the loop executes fastest
                if counter is an integer variable.

       start    A numeric expression; the starting value of counter.

         end    A numeric expression; the ending value of counter.

   increment    A numeric expression; the value by which counter is
                incremented or decremented with each iteration of the
                loop. Defaults to +1.

   ----------------------------------------------------------------------

      Notes:    BASIC begins processing of the FOR/NEXT block by setting
                counter equal to start. Then, if increment is positive and
                counter is not greater than end, the statements between
                the FOR statement and the NEXT statement are executed.
                When the NEXT statement is encountered, counter is
                increased by increment, and the process is repeated.
                Execution passes to the statement following the NEXT
                statement if counter is greater than end.

                If increment is negative, execution of the FOR/NEXT loop
                is terminated whenever counter becomes less than end.

                If increment is 0, execution of the FOR/NEXT loop
                continues until Ctrl-Break is pressed (unless one of the
                repeated instructions itself increments counter).

                Note that changes made within the FOR/NEXT loop to counter
                affect the number of times the loop instructions are
                executed; changes made to start, end, and increment,
                however, do not have this effect.

                There must be one and only one NEXT statement for each FOR
                statement. Inclusion of counter in the NEXT statement is
                optional; if counter is omitted, its value is assumed to
                be that of counter in the most recent FOR statement.

                FOR/NEXT loops may be nested within one another. Each FOR
                must be given a unique counter value and each nested FOR
                must have its NEXT statement appear within the enclosing
                FOR-NEXT block.

                Nested loops that have a common termination point may use
                a single NEXT statement with values of counter matching
                the values for each FOR statement.

                The loop is skipped completely if start is greater than
                end and increment is positive, or start is less than end
                and increment is negative.

See Also: DO LOOP NEXT WEND WHILE
This page created by ng2html v1.05, the Norton guide to HTML conversion utility. Written by Dave Pearson