Chapter 5. Repetition/Iteration Control Structure - Universiti Kuala Lumpur PDF

Summary

This presentation covers iteration control structures, including while, do-while, and for loops in Java programming. It includes examples of how to solve problems involving repetition using pseudocode and flowcharts.

Full Transcript

Chapter 5 epetition / Iteration Control Structure Topics of discussion : i. Solving problems involving repetition task with pseudocode and flowchart ii. Write a Java program using while, do while and for loop 2 Loop Concept Iteration...

Chapter 5 epetition / Iteration Control Structure Topics of discussion : i. Solving problems involving repetition task with pseudocode and flowchart ii. Write a Java program using while, do while and for loop 2 Loop Concept Iteration control structure involves with the repetition of the same statement or a block of statements. Each loop must satisfies the 3 elements that make the loop properly execute: i. the control variable must be initialized. ii. the control variable must be tested. iii. the control variable must be updated. There are three type of iterations: i. while loop (pre test loop) ii. do…while loop (post test loop) iii. for loop 3 while loop The while loop is similar to do…while loop. It differs in that the condition is placed on top of the loop. Consequently, a while loop will only be performed if the condition is true Conditional operators can be used to evaluate complex conditions as a whole 4 do…while loop A do…while loop will be performed once regardless whether the condition is true or not. Because the condition in a do…while loop is at the bottom, such a loop is always performed at least ONCE. 5 Problem # 1 Display “Hello” thousand(1000) times. After the task is finished, display “Done !” 6 Phase 1 : Problem Analysis Input Process Output counter ← 1 message DOWHILE counter

Use Quizgecko on...
Browser
Browser