1 / 24

6-5 Loops in C

6-5 Loops in C. C has three loop statements: the while , the for , and the do…while . The first two are pretest loops, and the the third is a post-test loop. We can use all of them for event-controlled and counter-controlled loops. Topics discussed in this section:. The while Loop

bhutchins
Download Presentation

6-5 Loops in C

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 6-5 Loops in C C has three loop statements: the while, the for, and the do…while. The first two are pretest loops, and the the third is a post-test loop. We can use all of them for event-controlled and counter-controlled loops. Topics discussed in this section: The while Loop The for Loop The do…while Loop The Comma Expression Computer Science: A Structured Programming Approach Using C

  2. FIGURE 6-9 C Loop Constructs Computer Science: A Structured Programming Approach Using C

  3. FIGURE 6-10 The while Statement Computer Science: A Structured Programming Approach Using C

  4. FIGURE 6-11 Compound while Statement Computer Science: A Structured Programming Approach Using C

  5. PROGRAM 6-1 Process-control System Example Computer Science: A Structured Programming Approach Using C

  6. PROGRAM 6-2 A while Loop to Print Numbers Computer Science: A Structured Programming Approach Using C

  7. PROGRAM 6-2 A while Loop to Print Numbers Computer Science: A Structured Programming Approach Using C

  8. PROGRAM 6-3 Adding a List of Numbers Computer Science: A Structured Programming Approach Using C

  9. PROGRAM 6-3 Adding a List of Numbers Computer Science: A Structured Programming Approach Using C

  10. Note A for loop is used when a loop is to be executed a known number of times. We can do the same thing with a while loop, but the for loop is easier to read and more natural for counting loops. Computer Science: A Structured Programming Approach Using C

  11. FIGURE 6-14 Comparing for and while Loops Computer Science: A Structured Programming Approach Using C

  12. PROGRAM 6-4 Example of a for Loop Computer Science: A Structured Programming Approach Using C

  13. PROGRAM 6-4 Example of a for Loop Computer Science: A Structured Programming Approach Using C

  14. PROGRAM 6-5 A Simple Nested for Loop Computer Science: A Structured Programming Approach Using C

  15. PROGRAM 6-5 A Simple Nested for Loop Computer Science: A Structured Programming Approach Using C

  16. FIGURE 6-15 do…while Statement Computer Science: A Structured Programming Approach Using C

  17. PROGRAM 6-6 Two Simple Loops Computer Science: A Structured Programming Approach Using C

  18. PROGRAM 6-6 Two Simple Loops Computer Science: A Structured Programming Approach Using C

  19. FIGURE 6-16 Pre- and Post-test Loops Computer Science: A Structured Programming Approach Using C

  20. PROGRAM 6-7 Adding a List with the do…while Computer Science: A Structured Programming Approach Using C

  21. PROGRAM 6-7 Adding a List with the do…while Computer Science: A Structured Programming Approach Using C

  22. FIGURE 6-17 Nested Comma Expression Computer Science: A Structured Programming Approach Using C

  23. PROGRAM 6-8 Comparison of while and do…while Computer Science: A Structured Programming Approach Using C

  24. PROGRAM 6-8 Comparison of while and do…while Computer Science: A Structured Programming Approach Using C

More Related