Đang chuẩn bị liên kết để tải về tài liệu:
Lecture An Introduction to Object-Oriented Programming with Java (4/e): Chapter 6 - C. Thomas Wu
Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Chapter 6 - Selection statements. In this chapter we will cover another group of control statements called repetition statements. Repetition statements control a block of code to be executed for a fixed number of times or until a certain condition is met. We will describe Java’s three repetition statements: while, do–while, and for. | Chapter 6 Repetition Statements 4th Ed Chapter 6 - ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Objectives After you have read and studied this chapter, you should be able to Implement repetition control in a program using while statements. Implement repetition control in a program using do-while statements. Implement a generic loop-and-a-half repetition control statement Implement repetition control in a program using for statements. Nest a loop repetition statement inside another repetition statement. Choose the appropriate repetition control statement for a given task Prompt the user for a yes-no reply using the showConfirmDialog method of JOptionPane. (Optional) Write simple recursive methods 4th Ed Chapter 6 - ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. We will study two forms of repetition statements in this lesson. They are while and do-while statement. Definition Repetition statements control a block of code to be executed for a fixed number of times or until a certain condition is met. Count-controlled repetitions terminate the execution of the block after it is executed for a fixed number of times. Sentinel-controlled repetitions terminate the execution of the block after one of the designated values called a sentinel is encountered. Repetition statements are called loop statements also. 4th Ed Chapter 6 - ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. In Chapter 5, we studied selection control statements. We will study in this chapter the second type of control statement, a repetition statement, that alters the sequential control flow. It controls the number of times a block of code is executed. In other words, a block of code is executed repeatedly until some condition occurs to stop the repetition. There are fundamentally two ways to stop the repetition—count-controlled and sentinel-controlled. The while Statement int sum = 0, . | Chapter 6 Repetition Statements 4th Ed Chapter 6 - ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Objectives After you have read and studied this chapter, you should be able to Implement repetition control in a program using while statements. Implement repetition control in a program using do-while statements. Implement a generic loop-and-a-half repetition control statement Implement repetition control in a program using for statements. Nest a loop repetition statement inside another repetition statement. Choose the appropriate repetition control statement for a given task Prompt the user for a yes-no reply using the showConfirmDialog method of JOptionPane. (Optional) Write simple recursive methods 4th Ed Chapter 6 - ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. We will study two forms of repetition statements in this lesson. They are while and do-while statement. Definition Repetition statements control a