|
DO LOOPs
- Start with DO and end with LOOP
- Indent the lines inside a DO loop
- repeats until the condition is met
- one execution of a DO loop is called a pass.
- There must be a primary lead (READ) or primary "condition" (count)
In a DO loop reading in data, the trailer record is called the sentinel record. Without the End Of File, you would get an infinite loop
numeric data: DO WHILE <> 0 or -1 string data: DO WHILE <> “EOF”
DO WHILE will execute the loop while the condition is true, and end when condition becomes false.
DO UNTIL will execute the loop until the condition becomes true.
Used if decision to terminate is at the top of the loop: Need to have primary lead executed at least once
DO WHILE LOOP
DO UNTIL LOOP
Used if the decision to terminate is at the bottom of the loop: No need for primary lead
DO LOOP WHILE
DO LOOP UNTIL
(see page 124 figure 5.3)
|