TAILIEUCHUNG - Absolute C++ (4th Edition) part 9

Absolute C++ (4th Edition) part 9. KEY BENEFIT: C++ programming concepts and techniques are presented in a straightforward style using understandable language and code. KEY TOPICS: C++ Basics; Flow of Control; Function Basics; Parameters and Overloading; Arrays; Structures and Classes; Constructors; Operator Overloading, Friends, and References; Strings; Pointers and Dynamic Arrays; Separate Compilation and Namespaces; Streams and File I/O; Recursion; Inheritance; Polymorphism and Virtual Functions; Templates; Linked Data Structures; Exception Handling; Standard Template Library; Patterns and UML. MARKET: Useful for both beginning and intermediate C++ programmers. . | Loops 8l Display A break Statement in a Loop 1 include iostream 2 using namespace std 3 int main 4 5 int number sum 0 count 0 6 cout Enter 4 negative numbers n 7 while count 4 8 9 cin number 10 if number 0 11 12 cout ERROR positive number 13 or zero was entered as the n 14 count th number Input ends 15 with the count th number. n 16 count th number was not added in. n 17 -- break 18 19 sum sum number 20 21 - cout sum is the sum of the first 22 count - 1 numbers. n 23 return 0 24 Sample Dialogue Enter 4 negative numbers -1 -2 3 -4 ERROR positive number or zero was entered as the 3rd number Input ends with the 3rd number. 3rd number was not added in -3 is the sum of the first 2 numbers. 82 Flow of Control Display A continue Statement in a Loop 1 include iostream 2 using namespace std 3 int main 4 5 int number sum 0 count 0 6 cout Enter 4 negative numbers ONE PER LINE n 7 8 9 10 11 12 13 14 15 while count 4 cin number if number 0 cout ERROR positive number or zero n Reenter that number and continue n ---- continue 16 17 18 sum sum number count 19 cout sum is the sum of the 20 count numbers. n 21 return 0 22 Sample Dialogue Enter 4 negative numbers ONE PER LINE 1 ERROR positive number or zero Reenter that number and continue -1 -2 3 ERROR positive number Reenter that number and continue -3 -4 -10 is the sum of the 4 numbers. Chapter Summary 83 Note that you never absolutely need a break or continue statement. The programs in Displays and can be rewritten so that neither uses either a break or continue statement. The continue statement can be particularly tricky and can make your code hard to read. It may be best to avoid the continue statement completely or at least use it only on rare occasions. NESTED LOOPS It is perfectly legal to nest one loop statement inside another loop statement. When doing so remember that any break or continue statement applies to the innermost loop or switch statement containing the break or continue statement. It is best to

TỪ KHÓA LIÊN QUAN
TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã 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.