Learn C++ in step-by-step lessons.
While Loops
A while loop has just a test. If the condition in the test is true the entire body of the loop executes, even if the condition becomes false inside the loop. When the body of the loop ends, the test is made again. A while loop executes 0 or more times.
Goals:
- Be able to use and understand while loops
Objectives:
- Be able to write a while loop to generate values
- Evaluate the output of a while loop
- Recognize an endless loop
- Be able to end a while loop with a sentinel value
- Be able to end a while loop by asking the user
- Find smallest, largest, total using a while loop
Please study the material at each of the links below.
- Compare for and while
- A loop to count
- Blast off 2 ways
- Doubling a value
- An endless loop
- Ending a total loop with a sentinel value
- Ending a total loop by asking if there are more
- Display "pass" or "fail" for each grade
- Finding the smallest and largest
Glossary for loopswhile lesson
Full Glossary