Questions: While Loops

5 questions to test your understanding

Score: 0 / 5
Question 1 Multiple Choice

Consider this loop: `count = 3; while (count > 0) { print(count); }`. What happens when it runs?

AIt prints 3, 2, 1 then stops
BIt prints 3 once, because the condition is checked after the body
CIt runs forever, printing 3 indefinitely
DIt prints nothing, because count starts at 3 which is greater than 0
Question 2 Multiple Choice

A loop starts with `count = 0` and has the condition `while (count < 5)`. How many times does the body execute?

A4 times (0, 1, 2, 3)
B5 times (0, 1, 2, 3, 4)
C6 times (0, 1, 2, 3, 4, 5)
DIt depends on what is inside the body
Question 3 True / False

A while loop checks its condition continuously — if the condition becomes false in the middle of the loop body, the loop exits immediately at that point.

TTrue
FFalse
Question 4 True / False

A while loop may execute its body zero times if its condition is false when the loop is first reached.

TTrue
FFalse
Question 5 Short Answer

Why must something inside a while loop's body eventually make the condition false? What happens if it doesn't, and how do you design against it?

Think about your answer, then reveal below.