C++ Loop Structure Review Questions
Review C++ loop structures with questions about while loops, loop conditions, counters, increments, repeated statements, and infinite loops.
Section 1: while Loop
- What is a loop in C++?
- Why do we use loops instead of writing the same statement repeatedly?
- What is a
whileloop in C++? Explain its purpose with an example. - What is the syntax of a
whileloop? - How does a
whileloop work? Explain its execution step by step. - What is the difference between a
whileloop and anifstatement? - What is an infinite loop? Explain why it occurs in a
whileloop and write a C++ example. - What happens if the condition of a
whileloop is false at the beginning? - Why is initialization important in a
whileloop? - What happens if the loop control variable is not updated?
- How can you use a
whileloop to repeatedly take input until the user enters0? - What is the difference between a
counter-controlled loopand asentinel-controlled loop? Give an example of each. - Can a
whileloop execute zero times? Explain with an example. - Identify three common mistakes students make when writing
whileloops and explain how to correct them.
Section 2: do-while Loop
- What is the difference between a
whileloop and ado-whileloop? - Why does a do-while loop execute at least once?
- Can a do-while loop execute when its condition is initially false? Explain with an example.