The third line is the beginning of a loop using the

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: iven in these figures. Both DO...WHILE and REPEAT...UNTIL are used for looping. In case of DO...WHILE, the looping will continue as long as the condition is true. The looping stops when the condition is not true. On the other hand, in case of REPEAT... UNITL, the looping continues until the condition becomes true. That is, the execution of the statements within the loop is repeated as long as the condition is not true. Notice that in case of DO... WHILE, the condition for looping is checked at the beginning of the loop. Hence if the condition is found to be false when the loop is first encountered, the processes in the loop will not be executed at all (not even once). On the other hand, in case of REPEAT... UNTIL, the condition for looping is checked at the end of the loop. Hence the processes inside the loop will be executed at least once. In both the DO...WHILE and REPEAT...UNITL, the loop must contain a statement that will change the condition that controls the loop. If it does not, the looping will continue without end, which is the case of an infinite loop. Remember that no program should contain an infinite loop. Also note that the condition is tested at the top of the loop in the DO...WHILE and at the bottom of the loop in the REPEAT... UNTIL. ENDDO marks the end of a DO...WHILE structure and UNTIL followed by some condition marks the end of the REPEAT...UNTIL structure. Condition? True Process1 Process n If false (a) Flow chart DO WHILE Condition Process 1 Process n ENDDO (b) Pseudocode Figure 11.18. Flowchart and pseudocode for DO...WHILE iteration structure. Sample Pseudocode The pseudocode version of the logic of the problem of Example 11.6 that was charted in Figure 11.9 is shown in Figure 11.20. In the pseudocode example, the first line initializes the value of Count to zero and the second line reads the input data of the first student. The third line is the beginning of a loop using the DO.. .WHILE structure. It indicates that the loop will continue so long as the trailer Sexc...
View Full Document

This document was uploaded on 04/07/2014.

Ask a homework question - tutors are online