Download presentation
Presentation is loading. Please wait.
1
Topics discussed in this section:
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
Process-control System Example
PROGRAM 6-1 Process-control System Example Computer Science: A Structured Programming Approach Using C
6
A while Loop to Print Numbers
PROGRAM 6-2 A while Loop to Print Numbers Computer Science: A Structured Programming Approach Using C
7
A while Loop to Print Numbers
PROGRAM 6-2 A while Loop to Print Numbers Computer Science: A Structured Programming Approach Using C
8
Adding a List of Numbers
PROGRAM 6-3 Adding a List of Numbers Computer Science: A Structured Programming Approach Using C
9
Adding a List of Numbers
PROGRAM 6-3 Adding a List of Numbers Computer Science: A Structured Programming Approach Using C
10
more natural for counting loops.
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
A Simple Nested for Loop
PROGRAM 6-5 A Simple Nested for Loop Computer Science: A Structured Programming Approach Using C
15
A Simple Nested for Loop
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
Adding a List with the do…while
PROGRAM 6-7 Adding a List with the do…while Computer Science: A Structured Programming Approach Using C
21
Adding a List with the do…while
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
Comparison of while and do…while
PROGRAM 6-8 Comparison of while and do…while Computer Science: A Structured Programming Approach Using C
24
Comparison of while and do…while
PROGRAM 6-8 Comparison of while and do…while Computer Science: A Structured Programming Approach Using C
25
Topics discussed in this section:
6-6 Loop Examples This section contains several short examples of loop applications. Each program demonstrates one or more programming concepts that you will find helpful in solving other problems. Topics discussed in this section: for Loops while LOOPS do…while LOOPS Computer Science: A Structured Programming Approach Using C
26
PROGRAM 6-9 Compound Interest
Computer Science: A Structured Programming Approach Using C
27
PROGRAM 6-9 Compound Interest
Computer Science: A Structured Programming Approach Using C
28
PROGRAM 6-9 Compound Interest
Computer Science: A Structured Programming Approach Using C
29
FIGURE 6-18 Print Right Triangle Flowchart and Pseudocode
Computer Science: A Structured Programming Approach Using C
30
Print Right Triangle Using Nested for
PROGRAM 6-10 Print Right Triangle Using Nested for Computer Science: A Structured Programming Approach Using C
31
Print Right Triangle Using Nested for
PROGRAM 6-10 Print Right Triangle Using Nested for Computer Science: A Structured Programming Approach Using C
32
Print Number Series Using User-specified Limit
PROGRAM 6-11 Print Number Series Using User-specified Limit Computer Science: A Structured Programming Approach Using C
33
Print Number Series Using User-specified Limit
PROGRAM 6-11 Print Number Series Using User-specified Limit Computer Science: A Structured Programming Approach Using C
34
PROGRAM 6-12 Print Calendar Month
Computer Science: A Structured Programming Approach Using C
35
PROGRAM 6-12 Print Calendar Month
Computer Science: A Structured Programming Approach Using C
36
PROGRAM 6-12 Print Calendar Month
Computer Science: A Structured Programming Approach Using C
37
Never use one variable to control two processes.
Note Never use one variable to control two processes. Computer Science: A Structured Programming Approach Using C
38
PROGRAM 6-13 Print Sum of Digits
Computer Science: A Structured Programming Approach Using C
39
PROGRAM 6-13 Print Sum of Digits
Computer Science: A Structured Programming Approach Using C
40
PROGRAM 6-14 Print Number Backward
Computer Science: A Structured Programming Approach Using C
41
PROGRAM 6-14 Print Number Backward
Computer Science: A Structured Programming Approach Using C
42
FIGURE 6-19 Design for Binary to Decimal
Computer Science: A Structured Programming Approach Using C
43
Convert Binary to Decimal
PROGRAM 6-15 Convert Binary to Decimal Computer Science: A Structured Programming Approach Using C
44
Convert Binary to Decimal
PROGRAM 6-15 Convert Binary to Decimal Computer Science: A Structured Programming Approach Using C
45
Convert Binary to Decimal
PROGRAM 6-15 Convert Binary to Decimal Computer Science: A Structured Programming Approach Using C
46
Convert Binary to Decimal
PROGRAM 6-15 Convert Binary to Decimal Computer Science: A Structured Programming Approach Using C
47
Convert Binary to Decimal
PROGRAM 6-15 Convert Binary to Decimal Computer Science: A Structured Programming Approach Using C
48
Convert Binary to Decimal
PROGRAM 6-15 Convert Binary to Decimal Computer Science: A Structured Programming Approach Using C
49
Convert Binary to Decimal
PROGRAM 6-15 Convert Binary to Decimal Computer Science: A Structured Programming Approach Using C
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.