Lecture C++ programming: from problem analysis to program design - Chapter 5: Control structures II (Repetition)

In this chapter, you will: Learn about repetition (looping) control structures; explore how to construct and use count-controlled, sentinel-controlled, flag-controlled, and eof-controlled repetition structures; examine break and continue statements; discover how to form and use nested control structures; | C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 5: Control Structures II (Repetition) C++ Programming: From Problem Analysis to Program Design, Fourth Edition Objectives In this chapter, you will: Learn about repetition (looping) control structures Explore how to construct and use count-controlled, sentinel-controlled, flag-controlled, and EOF-controlled repetition structures Examine break and continue statements Discover how to form and use nested control structures C++ Programming: From Problem Analysis to Program Design, Fourth Edition Why Is Repetition Needed? Repetition allows you to efficiently use variables Can input, add, and average multiple numbers using a limited number of variables For example, to add five numbers: Declare a variable for each number, input the numbers and add the variables together Create a loop that reads a number into a variable and adds it to a variable that contains the sum of the numbers C++ Programming: From | C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 5: Control Structures II (Repetition) C++ Programming: From Problem Analysis to Program Design, Fourth Edition Objectives In this chapter, you will: Learn about repetition (looping) control structures Explore how to construct and use count-controlled, sentinel-controlled, flag-controlled, and EOF-controlled repetition structures Examine break and continue statements Discover how to form and use nested control structures C++ Programming: From Problem Analysis to Program Design, Fourth Edition Why Is Repetition Needed? Repetition allows you to efficiently use variables Can input, add, and average multiple numbers using a limited number of variables For example, to add five numbers: Declare a variable for each number, input the numbers and add the variables together Create a loop that reads a number into a variable and adds it to a variable that contains the sum of the numbers C++ Programming: From Problem Analysis to Program Design, Fourth Edition while Looping (Repetition) Structure The general form of the while statement is: while is a reserved word Statement can be simple or compound Expression acts as a decision maker and is usually a logical expression Statement is called the body of the loop The parentheses are part of the syntax C++ Programming: From Problem Analysis to Program Design, Fourth Edition while Looping (Repetition) Structure (continued) Infinite loop: continues to execute endlessly Avoided by including statements in loop body that assure exit condition is eventually false C++ Programming: From Problem Analysis to Program Design, Fourth Edition while Looping (Repetition) Structure (continued) C++ Programming: From Problem Analysis to Program Design, Fourth Edition Designing while Loops C++ Programming: From Problem Analysis to Program Design, Fourth Edition Case 1: Counter-Controlled while Loops If you know exactly how many pieces of data .

Không thể tạo bản xem trước, hãy bấm tải xuống
TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.