Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computer Science: A Structured Programming Approach Using C1 6-7 Other Statements Related to Looping Three other C statements are related to loops: break,

Similar presentations


Presentation on theme: "Computer Science: A Structured Programming Approach Using C1 6-7 Other Statements Related to Looping Three other C statements are related to loops: break,"— Presentation transcript:

1 Computer Science: A Structured Programming Approach Using C1 6-7 Other Statements Related to Looping Three other C statements are related to loops: break, continue, and goto. The last statements, the goto, is not valid for structured programs and therefore is not discussed in this text. break continue Topics discussed in this section:

2 Computer Science: A Structured Programming Approach Using C2 FIGURE 6-20 break and Inner Loops

3 Computer Science: A Structured Programming Approach Using C3 PROGRAM 6-16The for and while as Perpetual Loops

4 Computer Science: A Structured Programming Approach Using C4 PROGRAM 6-17Using a break Flag

5 Computer Science: A Structured Programming Approach Using C5 FIGURE 6-21 The continue Statement

6 Computer Science: A Structured Programming Approach Using C6 PROGRAM 6-18continue Example

7 Computer Science: A Structured Programming Approach Using C7 6-8 Looping Applications In this section, we examine four common applications for loops: summation, product, smallest and largest, and inquiries. Although the uses for loops are virtually endless, these problems illustrate many common applications. Summation Powers Smallest and Largest Inquiries Topics discussed in this section:

8 Computer Science: A Structured Programming Approach Using C8 FIGURE 6-22 Summation and Product Loops

9 Computer Science: A Structured Programming Approach Using C9 PROGRAM 6-19Sum to EOF Function

10 Computer Science: A Structured Programming Approach Using C10 PROGRAM 6-19Sum to EOF Function

11 Computer Science: A Structured Programming Approach Using C11 PROGRAM 6-20Powers Function

12 Computer Science: A Structured Programming Approach Using C12 PROGRAM 6-20Powers Function

13 Computer Science: A Structured Programming Approach Using C13 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. Note

14 Computer Science: A Structured Programming Approach Using C14 FIGURE 6-23 Smallest and Largest Loops

15 Computer Science: A Structured Programming Approach Using C15 PROGRAM 6-21Smallest to EOF Function

16 Computer Science: A Structured Programming Approach Using C16 PROGRAM 6-21Smallest to EOF Function

17 Computer Science: A Structured Programming Approach Using C17 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. Note

18 Computer Science: A Structured Programming Approach Using C18 FIGURE 6-24 any and all Inquiries

19 Computer Science: A Structured Programming Approach Using C19 PROGRAM 6-22anyPositive to EOF Function

20 Computer Science: A Structured Programming Approach Using C20 PROGRAM 6-22anyPositive to EOF Function

21 Computer Science: A Structured Programming Approach Using C21 PROGRAM 6-23All Positive Function

22 Computer Science: A Structured Programming Approach Using C22 PROGRAM 6-22anyPositive to EOF Function


Download ppt "Computer Science: A Structured Programming Approach Using C1 6-7 Other Statements Related to Looping Three other C statements are related to loops: break,"

Similar presentations


Ads by Google