Objective:
At the end of the lesson the students shall be
able to:
Define while and do while loop.
understand the syntax of while and do while
loop.
create a program using while and do while
loop.
What is while
loop?
“While Loop” is used to
repeat a specific block of
code an unknown
number of times, until a
condition is met.
while loop syntax
Flowchart of while loop
Example 1: Display Numbers
from 1 to 5
Explanation:
Example #2:
Loop Update using prompt
What is do
while loop?
The do...while loop is a variant
of the while loop with one
important difference: the body
of do...while loop is executed
once before the condition is
checked.
do while loop syntax
Flowchart of do…..while loop
Example 1: Display Numbers
from 1 to 5
Explanation:
Example #2
Infinite while
loop
for vs while loops
Seatwork #3
Using while and do while loop, write a
program that will find the sum of positive
numbers. If the users enters a negative
number, the loops ends. The negative number
is not added to the sum.
Answer
Answer
Answer
Answer
while
loop
Answer
do while
loop