This preview shows page 1. Sign up to view the full content.
Unformatted text preview: posCount to 0. We test posCount against ten, and exit the loop when posCount reaches 11. How do we update the event? We increment posCount each time we read a positive value. Many languages have two additional looping structures. We said that the while structure is a pretest loop. Another type of looping structure is one where the testing occurs at the end of the loop. These loops are called posttest loops, for obvious reasons. Posttest loops always execute the loop Set sum to 0 Initialize sum to zero Set posCount to 0 Initialize event While (posCount <= 10) Test event Read a value If (value > 0) Test to see if event should be updated Set posCount to posCount + 1 Update event Set sum to sum + value Add value into sum ... Statement(s) following loop Read a value Initialize event While (value >= o) Test event ... Body of loop Read a value Update event ... Statement(s) following loop...
View Full Document
- Fall '10