Quarter-4-Lesson-1-Looping-with-while-statements-student-copy
Quarter-4-Lesson-1-Looping-with-while-statements-student-copy
z
LOOPING WITH
while
STATEMENTS
Jean T. Tumaneng
In this lesson, you will learn about:
z
while - do - endwhile
LOOP
or
structure
while - endwhile
z
z
Understanding
the Advantages
of Looping
Loop
z
follows while
eventually is false.
start
Declarations
num count = 0
while count < 4
output
“Hello”
count =
count + 1
endwhile
output
“Goodbye”
Ways to change the value of the Loop
z Control Variable
start
the loop
YES
control count < 4?
count = 4
output
“Goodbye”
stop
Ways to change the value of the Loop
z Control Variable
start
Retrieve a Declarations
num count
=0
new value
from an count < 4?
YES
input count
output
“Goodbye”
stop
Ways to change the value of the Loop
z Control Variable
start
Increment (+
Declarations
num count
+), or =0
increase, the
YES
loop control count < 4?
count = count + 1
output
“Goodbye”
stop
Ways to change the value of the Loop
z Control Variable
start
Declarations
Reduce, or num count
=8
decrement(--),
the loop control YES
count > 4?
variable
NO output “Hello”
count = count - 1
output
“Goodbye”
stop
z
input RESPONSE
RESPONSE YES
= “Y”?
NO output “Hello”
YES
NO
YES
NO
Inner Loop -
the loop that
is contained
a=2
a=2
z
b=4
b=4 while a < 5
output “Thank you!”
NO
a < 5?
YES c=1
while c < b
output
output
“Goodbye
“Thank you” output “Come
!”
Again!”
c=1
c=c+1
endwhile
NO
c < b?
YES a=a+1
a=a+1 output
endwhile
“Come
Again”
c=c+1
output “Goodbye”
a=2
z b=4
while a < 5
output “Thank you!”
c=1
while c < b
output “Come
Again!”
c=c+1
endwhile
a=a+1
endwhile
Avoiding
z
Common Loop Mistakes