tailieunhanh - Lecture Introduction to Java programming - Chapter 4: Loops
After completing this unit, you should be able: To write programs for executing statements repeatedly using a while loop, to develop a program for GuessNumber, to follow the loop design strategy to develop loops, to develop a program for SubtractionQuizLoop, to control a loop with a sentinel value,. | Chapter 4 Loops Motivations Suppose that you need to print a string (., "Welcome to Java!") a hundred times. It would be tedious to have to write the following statement a hundred times: ("Welcome to Java!"); So, how do you solve this problem? Opening Problem ("Welcome to Java!"); ("Welcome to Java!"); ("Welcome to Java!"); ("Welcome to Java!"); ("Welcome to Java!"); ("Welcome to Java!"); ("Welcome to Java!"); ("Welcome to Java!"); ("Welcome to Java!"); Problem: 100 times Introducing while Loops int count = 0; while (count Objectives To write programs for executing statements repeatedly using a while loop (§). To develop a program for GuessNumber and SubtractionQuizLoop (§). To follow the loop design strategy to develop loops (§). To develop a program for SubtractionQuizLoop (§). To control a loop with a sentinel value (§). To obtain large input from a file using input redirection rather than typing from the keyboard (§). To write loops using do-while statements (§). To write loops using for statements (§). To discover the similarities and differences of three types of loop statements (§). To write nested loops (§). To learn the techniques for minimizing numerical errors (§). To learn loops from a variety of examples (GCD, FutureTuition, MonteCarloSimulation) (§). To implement program control with break and continue (§). (GUI) To control a loop with a confirmation dialog (§). while Loop Flow Chart while (loop-continuation-condition) { // loop-body; Statement(s); } int count = 0; while (count Trace while Loop int count = 0; while (count Motivations Suppose that you need to print a string (., "Welcome to Java!") a hundred times. It would be tedious to have to write the following statement a hundred times: ("Welcome to Java!"); So, how do you solve this problem? Opening Problem ("Welcome to Java!"); ("Welcome to Java!"); ("Welcome to Java!"); ("Welcome to Java!"); ("Welcome to Java!"); ("Welcome to Java!"); ("Welcome to Java!"); ("Welcome to Java!"); ("Welcome to Java!"); Problem: 100 times Introducing while Loops int count = 0; while (count Objectives To write programs for executing statements repeatedly using a while loop (§). To develop a program for GuessNumber and SubtractionQuizLoop (§). To follow the loop design strategy to .
đang nạp các trang xem trước