Difficulty: Easy
Correct Answer: There should be a condition in the while loop
Explanation:
Introduction / Context:
This item tests your grasp of the required syntax for a while loop in C. The loop header must contain a parenthesized expression that can be evaluated to determine whether the next iteration should execute.
Given Data / Assumptions:
while() with empty parentheses.i and conditionally breaks.
Concept / Approach:
In C, while (expression) requires a valid scalar expression. An empty condition is a syntax error and will not compile. To create an intentional infinite loop, write while(1) (or for(;;)) rather than leaving the condition blank.
Step-by-Step Solution:
Parse header: while() → missing expression → syntax error.Fix: add a condition such as while (i <= 10) or while (1).Keep the break to terminate if needed.
Verification / Alternative check:
Compiling will emit an error like “expected expression before ‘)’ token.” Changing to while(1) or a proper condition compiles.
Why Other Options Are Wrong:
At least a semicolon — a semicolon after while creates an empty loop, not a fix here. Replace with for — unnecessary; while works when written correctly. No error — incorrect.
Common Pitfalls:
Accidentally leaving conditions blank; confusing deliberate empty loops (while(x--);) with missing conditions.
Final Answer:
There should be a condition in the while loop
Discussion & Comments