
















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A comprehensive introduction to looping with while statements in programming. It covers the advantages of looping, the use of loop control variables, the difference between definite and indefinite loops, nested loops, and common loop mistakes. Well-structured and uses clear examples to illustrate the concepts. It is suitable for beginners learning about programming concepts.
Typology: Slides
1 / 24
This page cannot be seen from the preview
Don't miss anything!

















In this lesson, you will learn about: The advantages of looping Using a loop control variable Difference between definite and indefinite loops Nested loops Avoiding common loop mistakes
Understanding the Advantages of Looping
Using a Loop Control Variable
Using a Definite Loop with a Counter Counter is any numeric variable that counts the number of times an event has occurred.
Three (3) separate actions should occur using a loop control variable:
Loop control variable is initialized. count < 4? Loop control variable is tested. output “Hello” count = count + 1 Loop control variable is altered. output “Goodbye” stop
Ways to change the value of the Loop Control Variable
start Declarations num count = 0 count < 4? output “Hello” count = 4 output “Goodbye” stop
Ways to change the value of the Loop Control Variable Retrieve a new value from an input device start Declarations num count = 0 count < 4? output “Hello” output “Goodbye” stop input count
Ways to change the value of the Loop Control Variable
start Declarations num count = 8 count > 4? output “Hello” count = count - 1 output “Goodbye” stop
Using an Indefinite Loop with a Sentinel Value Sentinel Value A preselected value that stops the execution of a program it represents an entry or exit point
start Declarations string RESPONSE output “Do you want to continue? Y or N >>” input RESPONSE while RESPONSE = “Y” output “Hello” output “Do you want to continue? Y or N >>” input RESPONSE endwhile output “Goodbye” stop
Nested LOOP