6-7 Other Statements Related to Looping
-
Upload
dai-herring -
Category
Documents
-
view
33 -
download
0
description
Transcript of 6-7 Other Statements Related to Looping
![Page 1: 6-7 Other Statements Related to Looping](https://reader030.fdocuments.in/reader030/viewer/2022032805/56813277550346895d990fee/html5/thumbnails/1.jpg)
Computer Science: A Structured Programming Approach Using C 1
6-7 Other Statements Related to Looping
Three other C statements are related to loops: break, Three other C statements are related to loops: break, continue, and goto. The last statements, the goto, is continue, and goto. The last statements, the goto, is not valid for structured programs and therefore is not not valid for structured programs and therefore is not discussed in this text.discussed in this text.
breakcontinue
Topics discussed in this section:Topics discussed in this section:
![Page 2: 6-7 Other Statements Related to Looping](https://reader030.fdocuments.in/reader030/viewer/2022032805/56813277550346895d990fee/html5/thumbnails/2.jpg)
Computer Science: A Structured Programming Approach Using C 2
FIGURE 6-20 break and Inner Loops
![Page 3: 6-7 Other Statements Related to Looping](https://reader030.fdocuments.in/reader030/viewer/2022032805/56813277550346895d990fee/html5/thumbnails/3.jpg)
Computer Science: A Structured Programming Approach Using C 3
PROGRAM 6-16 The for and while as Perpetual Loops
![Page 4: 6-7 Other Statements Related to Looping](https://reader030.fdocuments.in/reader030/viewer/2022032805/56813277550346895d990fee/html5/thumbnails/4.jpg)
Computer Science: A Structured Programming Approach Using C 4
PROGRAM 6-17 Using a break Flag
![Page 5: 6-7 Other Statements Related to Looping](https://reader030.fdocuments.in/reader030/viewer/2022032805/56813277550346895d990fee/html5/thumbnails/5.jpg)
Computer Science: A Structured Programming Approach Using C 5
FIGURE 6-21 The continue Statement
![Page 6: 6-7 Other Statements Related to Looping](https://reader030.fdocuments.in/reader030/viewer/2022032805/56813277550346895d990fee/html5/thumbnails/6.jpg)
Computer Science: A Structured Programming Approach Using C 6
PROGRAM 6-18 continue Example
![Page 7: 6-7 Other Statements Related to Looping](https://reader030.fdocuments.in/reader030/viewer/2022032805/56813277550346895d990fee/html5/thumbnails/7.jpg)
Computer Science: A Structured Programming Approach Using C 7
6-8 Looping Applications
In this section, we examine four common applications In this section, we examine four common applications for loops: summation, product, smallest and largest, and for loops: summation, product, smallest and largest, and inquiries. Although the uses for loops are virtually inquiries. Although the uses for loops are virtually endless, these problems illustrate many common endless, these problems illustrate many common applications.applications.
SummationPowersSmallest and LargestInquiries
Topics discussed in this section:Topics discussed in this section:
![Page 8: 6-7 Other Statements Related to Looping](https://reader030.fdocuments.in/reader030/viewer/2022032805/56813277550346895d990fee/html5/thumbnails/8.jpg)
Computer Science: A Structured Programming Approach Using C 8
FIGURE 6-22 Summation and Product Loops
![Page 9: 6-7 Other Statements Related to Looping](https://reader030.fdocuments.in/reader030/viewer/2022032805/56813277550346895d990fee/html5/thumbnails/9.jpg)
Computer Science: A Structured Programming Approach Using C 9
PROGRAM 6-19 Sum to EOF Function
![Page 10: 6-7 Other Statements Related to Looping](https://reader030.fdocuments.in/reader030/viewer/2022032805/56813277550346895d990fee/html5/thumbnails/10.jpg)
Computer Science: A Structured Programming Approach Using C 10
PROGRAM 6-19 Sum to EOF Function
![Page 11: 6-7 Other Statements Related to Looping](https://reader030.fdocuments.in/reader030/viewer/2022032805/56813277550346895d990fee/html5/thumbnails/11.jpg)
Computer Science: A Structured Programming Approach Using C 11
PROGRAM 6-20 Powers Function
![Page 12: 6-7 Other Statements Related to Looping](https://reader030.fdocuments.in/reader030/viewer/2022032805/56813277550346895d990fee/html5/thumbnails/12.jpg)
Computer Science: A Structured Programming Approach Using C 12
PROGRAM 6-20 Powers Function
![Page 13: 6-7 Other Statements Related to Looping](https://reader030.fdocuments.in/reader030/viewer/2022032805/56813277550346895d990fee/html5/thumbnails/13.jpg)
Computer Science: A Structured Programming Approach Using C 13
To find the sum of a series, the result is initialized to 0;to find the product of a series, the result is initialized to 1.
NoteNote
![Page 14: 6-7 Other Statements Related to Looping](https://reader030.fdocuments.in/reader030/viewer/2022032805/56813277550346895d990fee/html5/thumbnails/14.jpg)
Computer Science: A Structured Programming Approach Using C 14
FIGURE 6-23 Smallest and Largest Loops
![Page 15: 6-7 Other Statements Related to Looping](https://reader030.fdocuments.in/reader030/viewer/2022032805/56813277550346895d990fee/html5/thumbnails/15.jpg)
Computer Science: A Structured Programming Approach Using C 15
PROGRAM 6-21 Smallest to EOF Function
![Page 16: 6-7 Other Statements Related to Looping](https://reader030.fdocuments.in/reader030/viewer/2022032805/56813277550346895d990fee/html5/thumbnails/16.jpg)
Computer Science: A Structured Programming Approach Using C 16
PROGRAM 6-21 Smallest to EOF Function
![Page 17: 6-7 Other Statements Related to Looping](https://reader030.fdocuments.in/reader030/viewer/2022032805/56813277550346895d990fee/html5/thumbnails/17.jpg)
Computer Science: A Structured Programming Approach Using C 17
To find the largest, we need to initialize the smallest variable to a very small number, such as INT_MIN.
To find the smallest, we need to initialize the result to a very large number, such as INT_MAX.
NoteNote
![Page 18: 6-7 Other Statements Related to Looping](https://reader030.fdocuments.in/reader030/viewer/2022032805/56813277550346895d990fee/html5/thumbnails/18.jpg)
Computer Science: A Structured Programming Approach Using C 18
FIGURE 6-24 any and all Inquiries
![Page 19: 6-7 Other Statements Related to Looping](https://reader030.fdocuments.in/reader030/viewer/2022032805/56813277550346895d990fee/html5/thumbnails/19.jpg)
Computer Science: A Structured Programming Approach Using C 19
PROGRAM 6-22 anyPositive to EOF Function
![Page 20: 6-7 Other Statements Related to Looping](https://reader030.fdocuments.in/reader030/viewer/2022032805/56813277550346895d990fee/html5/thumbnails/20.jpg)
Computer Science: A Structured Programming Approach Using C 20
PROGRAM 6-22 anyPositive to EOF Function
![Page 21: 6-7 Other Statements Related to Looping](https://reader030.fdocuments.in/reader030/viewer/2022032805/56813277550346895d990fee/html5/thumbnails/21.jpg)
Computer Science: A Structured Programming Approach Using C 21
PROGRAM 6-23 All Positive Function
![Page 22: 6-7 Other Statements Related to Looping](https://reader030.fdocuments.in/reader030/viewer/2022032805/56813277550346895d990fee/html5/thumbnails/22.jpg)
Computer Science: A Structured Programming Approach Using C 22
PROGRAM 6-22 anyPositive to EOF Function