Professional Documents
Culture Documents
Loops and Iteration: Introduction To Algorithms and Programming
Loops and Iteration: Introduction To Algorithms and Programming
Loops and Iteration: Introduction To Algorithms and Programming
REVIEW
▸ Conditional statements:
REVIEW
▸ Write C++ program to display the largest number among three numbers
REVIEW
LOOPS AND ITERATION
WHAT IS A LOOP?
▸ It is a conditional iterative statement which is used to check for certain
conditions and then repeatedly execute a block of code as long as those
conditions are met
LOOPS AND ITERATION
START
LOOPS AND FLOW CHARTS
SHUT DOWN WATER TAP
OPEN WATER TAP
END
CLEAN HANDS WITH WATER
YES ARE NO
HANDS
CLEAN?
LOOPS AND ITERATION
ITERATIONS
While loops
Do-while loops
LOOPS AND ITERATION
FOR LOOPS
WHILE LOOPS
▸ Used when the number of iterations isn’t know, but the condition is clear
LOOPS AND ITERATION
DO-WHILE LOOPS
▸ This loop will execute the code block once, before checking if the condition is
true, then it will repeat the loop as long as the condition is true.
LOOPS AND ITERATION
▸ Write a c++ program that prints “Hello world!” five times on the screen
Without for loop With for loop
LOOPS AND ITERATION
▸ Write a C++ program that prints numbers between two numbers chosen by the
user
LOOPS AND ITERATION
▸ Write a C++ program that sums up the numbers between two numbers chosen
by the user and then find the average of those number.
LOOPS AND ITERATIONS
▸ Write a C++ program that prints “Hello” ten times using while loop
LOOPS AND ITERATION
▸ Write a C++ program that reverse a number (example: 4392 => 2934)
LOOPS AND ITERATION
EXAMPLE 7