A WHILE-DO control structure allows us to create a repetitive code loop that will DO (execute) a block of code WHILE a specific conditional expression evaluates to TRUE. WHILE-DO is different from REPEAT-UNTIL, both because it may need a BEGIN-END structure to define the block of code to be executed repetitively (REPEAT-UNTIL does not), and because it has different timings for the evaluation of the exit condition.
The syntax of the WHILE-DO control structure is as follows:
WHILE <Condition> DO <Statement>
The Condition can be any Boolean expression that evaluates to TRUE or FALSE. The Statement can be simple or the most complex compound BEGIN-END statement. Most WHILE-DO loops will be based on a BEGIN-END block of code. The Condition will be evaluated at the beginning of the loop. When it evaluates to FALSE, the loop will terminate. Thus, a WHILE-DO loop can be exited without processing.
A WHILE-DO structure to process data in the 10-element array CustSales ...