CabMasterPro User Guide
In This Topic
    Loops
    In This Topic

    Loop Structures

    The two different types of loop structures available are: those that only loop a set number of times, and those that loop continuously until a certain condition is met (i.e. an expression evaluates to TRUE). When using the latter type, make sure that it is possible for the terminating condition to be met, otherwise an infinite loop will occur.

    Loops can also be categorised into pre-test or post-test loops, depending on whether the condition is tested before the loop runs or after. The difference is that a post-test loop must run at least once.

    WHILE WEND

    Repeatedly runs a set of instructions while a condition is true (pre-test).

    Syntax:
    WHILE loop_condition stat_list WEND

    WHILE ( loop_condition ) { stat_list }

    WHILE ( loop_condition ) DO BEGIN stat_list END

    DO WHILE / UNTIL

    Repeatedly runs a set of instructions while a condition is true, or until the condition is false (pre-test).

    Syntax:
    DO WHILE loop_condition stat_list LOOP

    DO UNTIL loop_condition stat_list LOOP

    DO LOOP WHILE / UNTIL

    Repeatedly runs a set of instructions while a condition is true, or until the condition is false (post-test).

    Syntax:
    DO stat_list LOOP WHILE loop_condition

    DO stat_list LOOP UNTIL loop_condition

    DO { stat_list } WHILE ( loop_condition )

    DO BEGIN stat_list END [LOOP] WHILE ( loop_condition )

    REPEAT stat_list UNTIL loop_condition

    FOR

    Runs a set of instructions, first evaluating the start expressions, looping while the condition is true, and executing the iteration expression each time through

    Syntax:
    FOR ( [ start ] ; [ condition ] ; [iteration] ) statement

    FOR ( [ start ] ; [ condition ] ; [iteration] ) { stat_list }

    FOR NEXT

    Runs a set of instructions, stepping a variable each time, until an ending value is reached

    Syntax:
    FOR count [ = | := ] start_count [ TO | DOWNTO ]end_count [ STEP step_amount ] stat_list [ NEXT [ count ] | END FOR ]

    FOR count [ = | := ] start_count [ TO | DOWNTO ]end_count [ STEP step_amount ] { stat_list }

    FOR count [ = | := ] start_count [ TO | DOWNTO ]end_count [ DO ] BEGIN stat_list END


    FOR EACH NEXT

    Runs a set of instructions one for each value in an array

    Syntax:
    FOR EACH id IN array statlist NEXT id

    FOR EACH id IN array statlist END FOR

    FOR EACH id IN array { statlist }

    FOR EACH id IN array [ DO ] BEGIN statlist END

    FOR EACH key,value IN map statlist NEXT id

    FOR EACH key,value IN map statlist END FOR

    FOR EACH key,value IN map { statlist }

    FOR EACH key,value IN map [ DO ] BEGIN statlist END