Flow Control
Like all programming languages, PowerBASIC contains several structures to determine which blocks of code to execute and how often to repeat them. The structures can be summarized into the following categories.

Here is a summary of the specific PowerBASIC structures involved. These will be discussed in more detail further down this page.

Conditional Execution
Like all languages, PowerBASIC supports several flow-control structures. These allow a programmer to use the value of an expression to determine which PowerBASIC statements to execute.

Conditional Looping
Here are examples of each. The PowerBASIC FOR/NEXT structure also provides a means of repeating a block of statements a specific number of times, as in the following example.

Here are examples of each.

Enumerated Looping
With enumerated looping a program can specify the number of times that a block of statements can be executed. The FOR/NEXT structure is the only enumerated looping structure provided by PowerBASIC.

     FOR i = 1 TO 100
         <statements>          'executed 100 times
     NEXT i

     FOR i = 10 TO 100 STEP 5
         <statements>          'executed 19 times
     NEXT i

In the first example, the block of statements will execute 100 times. The value of i starts at 10 and is incremented by a value of 1 for each iteration of the loop. When i reaches the value of 101, the loop is exited.

The second example is similar, except that the value of i is incremented by a value of 5 for each iteration of the loop.

Unconditional Branching
These functions jump to the code at label or line number - without checking the value of an expression as was the case with On..GoTo and On..GoSub..

The GOTO does not return to the point where the call was made, whereas the GOSUB will return to the calling point once it reaches a RETURN statement. Both functions can only call code within the current scope.

Here is an example of each.

      GoTo 100     'jumps immediately to line 100
      a$ = 5       'skipped by the GoTo
  100 a$ = 6       'a$ is now 6


      GoSub 100    'jumps immediately to line 100
   99 a$ = 5       'skipped by the GoTo, but executed by Return 
      Dialog End
  100 a$ = 6       'a$ is now 6
      Return       'returns to line following GoSub

In-Loop Redirection
PowerBASIC provides two methods for changing the order of executing statements within a loop - exit and iterate.

Here are examples of each.

    IF x>2 THEN
       <statements>
       EXIT IF
       <statements>  'will not be executed
    END

    FOR i = 2 TO 200
        IF i > 12 and i < 20 THEN
            ITERATE FOR
        END IF
        <statements>   'skipped for values of 13 to 19
    NEXT i    

If you have any questions or corrections, please let me know.