guides:programming:programmers_reference_manual:loop

You were redirected here from UNTIL statement.

Loop statement

Marks the beginning of a group of statements, where the group is to be executed repeatedly, until the test expression is satisfied.

Loop

  [statements]

[While test] [Do]

  [statements]

[Until test] [Do]

  [statements]

Repeat

The Loop statement has the following parameters.

ParameterDescription
statementsAny statements that follow Loop are initially executed, and then any While or Until test is evaluated to determine whether its value is true (non-zero) or false (zero).
testAn expression that equates to a Boolean value - true (non-zero) or false (zero).
WhileIf the While format is used and the test evaluates to zero or null (""), the program control passes immediately out of the loop to the next statement after Repeat. But as long as the test evaluates to true, that is, while a certain specification has been met, the program will continue to loop.
UntilIf the Until format is used and the test evaluates to non-zero, the program control passes immediately out of the loop to the next statement after Repeat. But as long as the test evaluates to false, that is, until a certain specification has been met, the program will continue to loop.

Loop While true.
Loop Until false.

The Do following the Until and While statements is optional. You may use any number of Until and While tests in a single Loop…Repeat structure.

     * loop through selected records
     $Insert logical
     $Insert rlist_equates
     $Insert order_equates
     
     Open 'ORDERS' To f_orders Else
        Call Msg(@Window, 'Unable to Open ORDERS')
        Return ''
     end
     
     Call Rlist('SELECT ORDERS WITH ORDER_AGE LT "30"', target_activelist$)
     
     * total the multivalued QTY from all the selected records
     result =  0
     eof = false$
     Loop
          Readnext id Else eof = true$
     Until eof
          Read rec From f_orders, id Then
              result += Sum(rec<order_qty$>)
          end
     repeat

Return result
     * Use Loop + bremove to iterate across list of items. bRemove it the utf8 friendly version of the Remove statement
     col = ""
     Loop
          bRemove item From list At col Setting mark
          If item <> "" Then
             * Process it
             * .....
          end
     While mark
     repeat
     * Iterate across a comma delimited list using [] and col2() operators
     * This example uses UTF8 friendly syntax, ( var[p1,p2,flag] and bCol2() ) which runs faster in UTF8 mode.
     list = "comma delimited string initialized elsewhere'
     p = 1
     delim = ','
     delimLen = Blen(delim)
     Loop
          item = list[p,delim,1];p += Bcol2() + delimLen
          If Blen(item) Then
               // process it ....
          End
     While p Lt Blen(list)
     repeat

  • guides/programming/programmers_reference_manual/loop.txt
  • Last modified: 2024/06/19 20:20
  • by 127.0.0.1