Recall & Review
beginner
What is the basic structure of a
while loop in C#?A
while loop repeatedly executes a block of code as long as its condition is true. The structure is:<br>while (condition) {<br> // code to repeat<br>}Click to reveal answer
beginner
When does the condition in a
while loop get evaluated?The condition is checked before each iteration. If the condition is false at the start, the loop body does not run at all.
Click to reveal answer
intermediate
What happens if the
while loop condition never becomes false?The loop runs forever, causing an infinite loop. This can freeze or crash the program if not stopped.
Click to reveal answer
intermediate
How can you safely exit a
while loop before the condition becomes false?You can use the
break statement inside the loop to exit immediately when a certain condition is met.Click to reveal answer
intermediate
Explain the difference between
while and do-while loops.while checks the condition before running the loop body, so it may run zero times.<br>do-while runs the loop body first, then checks the condition, so it runs at least once.Click to reveal answer
When is the condition in a
while loop checked?✗ Incorrect
The
while loop checks its condition before every iteration to decide whether to run the loop body.What happens if the
while loop condition is false at the start?✗ Incorrect
If the condition is false initially, the
while loop skips the body completely.Which statement can be used to exit a
while loop early?✗ Incorrect
The
break statement immediately stops the loop and continues with the code after it.What is a risk of a
while loop if the condition never becomes false?✗ Incorrect
If the condition never becomes false, the
while loop runs forever, causing an infinite loop.How does a
do-while loop differ from a while loop?✗ Incorrect
do-while loops run the loop body first, then check the condition, so they always run at least once.Describe how a
while loop executes step-by-step in C#.Think about what happens before and after each time the loop runs.
You got /4 concepts.
Explain why it is important to update variables inside a
while loop.Consider what happens if the condition never changes.
You got /3 concepts.