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 specified condition is true.
Click to reveal answer
beginner
How does the execution order of a do-while loop differ from a while loop?
In a do-while loop, the code block runs first, then the condition is checked. In a while loop, the condition is checked first before running the code block.
Click to reveal answer
beginner
What happens if the condition in a do-while loop is false on the first check?
The code inside the do-while loop still runs once before the condition is checked and the loop stops if the condition is false.
Click to reveal answer
beginner
Write the basic syntax of a do-while loop in C#.
do {
// code to execute
} while (condition);
Click to reveal answer
beginner
Why might you choose a do-while loop over a while loop?
You choose a do-while loop when you want the code inside the loop to run at least once, regardless of the condition.
Click to reveal answer
What is guaranteed when using a do-while loop?
✗ Incorrect
A do-while loop always runs the code block once before checking the condition.
Where is the condition checked in a do-while loop?
✗ Incorrect
The condition is checked after the loop body executes in a do-while loop.
Which of these is the correct syntax for a do-while loop in C#?
✗ Incorrect
Option A shows the correct do-while loop syntax.
If the condition is false initially, how many times does the do-while loop run?
✗ Incorrect
The do-while loop runs once before checking the condition.
Which scenario is best suited for a do-while loop?
✗ Incorrect
Do-while loops ensure the code runs at least once, regardless of the condition.
Explain how a do-while loop works and how it differs from a while loop.
Think about when the condition is checked in each loop.
You got /4 concepts.
Describe a real-life situation where a do-while loop would be useful.
Imagine you want to show a menu and ask for input at least once.
You got /3 concepts.