Choose the best statement with respect to following three program snippets.
<br>
<br>
for (i = 0; i < 10; i++)<br>
{<br>
<br>
continue ;<br>
<br>
}<br>
<br>
i = 0;<br>
while (i < 10)<br>
{<br>
<br>
continue ;<br>
<br>
i++;<br>
}<br>
<br>
i = 0;<br>
do <br>
{<br>
<br>
continue ;<br>
<br>
i++;<br>
} while (i < 10);<br>
|
(A) All the loops are equivalent i.e. any of the three can be chosen and they all will perform exactly same.
(B) continue can't be used with all the three loops in C.
(C) After hitting the continue; statement in all the loops, the next expression to be executed would be controlling expression (i.e. i < 10) in all the 3 loops.
(D) None of the above is correct.
Answer: (D)
Explanation:
First and foremost, continue can be used in any of the 3 loops in C. In case of “for” loop, when continue is hit, the next expression to be executed would be i++ followed by controlling expression (i.e. i < 10). In case of “while” loop, when continue is hit, the next expression to be executed would be controlling expression (i.e. i < 10). In case of “do-while” loop, when continue is hit, the next expression to be executed would be controlling expression (i.e. i < 10). That’s why “while” and “do-while” loops would behave exactly same but not the “for” loop. Just to re-iterate, i++ would be executed in “for” loop when continue is hit.
Quiz of this Question
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
30 Oct, 2021
Like Article
Save Article