A repeating sequence in a program. Most software programs have a main loop and a series of minor loops nested within. Learning how to set up loops is fundamental programming logic. For a detailed look at an actual loop, see
event loop.
Loops are accomplished by various programming structures that have a beginning, body and end. The beginning generally tests the condition that keeps the loop going. The body comprises the repeating statements, and the end points back to the beginning. In assembly language, the programmer writes a GOTO instruction as in the following pseudocode example that counts to 10. See
pseudocode.
move "0" to EventCounter
EventLoop add "1" to EventCounter
compare EventCounter to "10"
goto EventLoop if unequal
stop
In a high-level language, the pointer back to the beginning is generated by the interpreter or compiler as in this pseudocode example, which uses a WHILE loop. See
pseudocode and
do loop.
EventCounter = 0
do while EventCounter not equal to 10
EventCounter = EventCounter + 1
enddo
stop
Batch Print the Invoices
This batch processing example reads order records and prints invoices. After printing date and bill-to/ship-to addresses, the program prints a variable number of line items. The line item loop is repeated as many times as required.