Recall & Review
beginner
What is a do–while loop in C?
A do–while loop is a control flow statement that executes a block of code at least once, and then repeats the loop as long as a given condition is true.
Click to reveal answer
beginner
How does a do–while loop differ from a while loop?
A do–while loop runs the code block first, then checks the condition. A while loop checks the condition first before running the code block.
Click to reveal answer
beginner
What is the syntax of a do–while loop in C?
Syntax:<br>
do {
// code to execute
} while (condition);<br>The code inside the do block runs first, then the condition is checked.Click to reveal answer
intermediate
Why is the semicolon required after the while(condition) in a do–while loop?
The semicolon marks the end of the do–while statement. It is required because the while(condition) acts like a statement that controls the loop repetition.
Click to reveal answer
beginner
Can a do–while loop run zero times?
No. A do–while loop always runs the code block at least once before checking the condition.
Click to reveal answer
What happens first in a do–while loop?
✗ Incorrect
In a do–while loop, the code block runs first before the condition is checked.
Which symbol is mandatory after the while(condition) in a do–while loop?
✗ Incorrect
A semicolon (;) is required after the while(condition) to end the do–while statement.
If the condition in a do–while loop is false initially, how many times does the loop run?
✗ Incorrect
The do–while loop runs the code block once before checking the condition, so it runs once even if the condition is false.
Which of these is the correct syntax for a do–while loop?
✗ Incorrect
The correct syntax is: do { /* code */ } while (condition);
Which loop guarantees the code runs at least once?
✗ Incorrect
Only the do–while loop guarantees the code runs at least once before checking the condition.
Explain how a do–while loop works and when you might use it.
Think about situations where you want to ask a question after doing something.
You got /4 concepts.
Write the syntax of a do–while loop and describe each part.
Remember the semicolon after the while condition.
You got /5 concepts.