Lecture Java™ How to Program (8/e) - Chapter 5: Control statements (Part II)

Chapter 4 - Control statements (Part II). After completing this chapter, students will be able to: The essentials of counter-controlled repetition, to use the for and do while repetition statements to execute statements in a program repeatedly, to understand multiple selection using the switch selection statement, to use the break and continue program control statements to alter the flow of control, to use the logical operators to form complex conditional expressions in control statements. | Java™ How to Program, 8/e (C) 2010 Pearson Education, Inc. All rights reserved. (C) 2010 Pearson Education, Inc. All rights reserved. (C) 2010 Pearson Education, Inc. All rights reserved. for repetition statement do while repetition statement switch multiple-selection statement break statement continue statement Logical operators Control statements summary. (C) 2010 Pearson Education, Inc. All rights reserved. Counter-controlled repetition requires a control variable (or loop counter) the initial value of the control variable the increment (or decrement) by which the control variable is modified each time through the loop (also known as each iteration of the loop) the loop-continuation condition that determines if looping should continue. (C) 2010 Pearson Education, Inc. All rights reserved. (C) 2010 Pearson Education, Inc. All rights reserved. In Fig. , the elements of counter-controlled repetition are defined in lines 8, 10 and 13. Line 8 declares the . | Java™ How to Program, 8/e (C) 2010 Pearson Education, Inc. All rights reserved. (C) 2010 Pearson Education, Inc. All rights reserved. (C) 2010 Pearson Education, Inc. All rights reserved. for repetition statement do while repetition statement switch multiple-selection statement break statement continue statement Logical operators Control statements summary. (C) 2010 Pearson Education, Inc. All rights reserved. Counter-controlled repetition requires a control variable (or loop counter) the initial value of the control variable the increment (or decrement) by which the control variable is modified each time through the loop (also known as each iteration of the loop) the loop-continuation condition that determines if looping should continue. (C) 2010 Pearson Education, Inc. All rights reserved. (C) 2010 Pearson Education, Inc. All rights reserved. In Fig. , the elements of counter-controlled repetition are defined in lines 8, 10 and 13. Line 8 declares the control variable (counter) as an int, reserves space for it in memory and sets its initial value to 1. The loop-continuation condition in the while (line 10) tests whether the value of the control variable is less than or equal to 10 (the final value for which the condition is true). Line 13 increments the control variable by 1 for each iteration of the loop. (C) 2010 Pearson Education, Inc. All rights reserved. (C) 2010 Pearson Education, Inc. All rights reserved. (C) 2010 Pearson Education, Inc. All rights reserved. (C) 2010 Pearson Education, Inc. All rights reserved. (C) 2010 Pearson Education, Inc. All rights reserved. for repetition statement Specifies the counter-controlled-repetition details in a single line of code. Figure reimplements the application of Fig. using for. (C) 2010 Pearson Education, Inc. All rights reserved. (C) 2010 Pearson Education, Inc. All rights reserved. When the for statement begins executing, the control variable is .

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.