You use nested loops to obtain multiple occurrences of multiple records. Loops that are not nested obtain multiple occurrences of a single record. You can map any loop records to repeated record blocks on your screen, or you can loop on records to calculate field totals and display just the calculation results.
When you define two loop calls in a program, the first loop is an outer loop, and the second loop is an inner (nested) loop. The nested loop executes repeatedly each time that the outer loop executes, and obtains all records that satisfy the outer loop record key. For example, you might want to loop on all order records of a particular customer, and loop on all detail records of all the order records.
You also might want to loop on a record to obtain a certain record occurrence that you loop on again, and display just the second loop records. For example, if your program must display all items to be included in the next shipment to a certain customer, you first loop on all outstanding orders for the customer to determine which order ships next. You then loop on that order to obtain all its detail records.
To indicate that the inner loop is nested within the outer loop, Online Express assigns a default nesting level value of 1 to it on the Attributes dialog box. The outer loop nesting level is 0, indicating that it is not nested.
When you define more than two loops, each loop is nested within the previous loop. That is, the second loop is nested within the first, and the third loop is nested within the second. The default nesting level of the third loop is 2. You can define as many nested loops in your program as you need.