[<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
FOR...NEXT

    FOR...NEXT permits you to accomplish a looping operation for a range of
    expressions, where you may optionally increment or decrement the range
    expression.

Syntax

    FOR <memvar> = <exp N1> to <exp N2> [STEP <exp N3>]
        <commands>...
        [EXIT]
        <commands>...
    NEXT

Arguments

    <memvar> is the loop control variable.

    <expN1> is the initial value assigned to the control variable and the
    lower boundary of the looping range.

    <expN2> is the upper boundary of the looping range.

Options

    Step: The STEP clause sets the increment of the control variable to
    <expN3>.  If no STEP clause is specified, the default increment is one.

    Exit: The EXIT clause unconditionally branches control from within
    the FOR..NEXT control structure to the statement immediately following
    the NEXT statement.

Usage

    FOR...NEXT allows you to loop from an initial value of a control
    variable to some upper boundary moving through the range of values of
    the control variable for a specified increment (or decrement).  Each
    time the FOR statement executes, Clipper evaluates all command line
    expressions.  This means that the upper boundary and increment are
    dynamic and can change as the construct operates.

Example

    The FOR...NEXT construct is particularly useful for traversing arrays.

    * to walk forward through an entire array
    len_array = LEN(array)                   
    FOR i = 1 TO len_array                   
       <commands>...                         
    NEXT                                     

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