APCO 1P93 Lecture Notes - Lecture 8: Duplicate Code
Document Summary
A repetition structure causes a statement or set of statements to execute repeatedly. While loop: while a condition is true, do some task. Do-while loop: do some task, while condition is true. Do-until loop: do some task, while a condition is false (or until it"s true) With all loops, be careful not to create infinite loops always provide a way to break out. Figure 5-1: the logic of a while loop. To run a program multiple times, modules can be put within a loop. Figure 5-8 flowchart for the main module in. Loop iterates until a condition is true, but not all languages support this type of loop. Figure 5-10: the logic of a do-until loop. A count-controlled loop iterates a specific number of times. A for loop is best used for this situation. For countervariable = startingvalue to maxvalue statement statement. There is an initialization, test, and increment expression that controls the loop.