Skip to content
Related Articles

Related Articles

Save Article
Improve Article
Save Article
Like Article

C Quiz – 105 | Question 1

  • Difficulty Level : Easy
  • Last Updated : 28 Jun, 2021

Choose the best statement with respect to following three program snippets.

Take a step-up from those "Hello World" programs. Learn to implement data structures like Heap, Stacks, Linked List and many more! Check out our Data Structures in C course to start learning today.




/*Program Snippet 1 with for loop*/
for (i = 0; i < 10; i++)
{
   /*statement1*/
   continue;
   /*statement2*/
}
  
/*Program Snippet 2 with while loop*/
i = 0;
while (i < 10)
{
   /*statement1*/
   continue;
   /*statement2*/
   i++;
}
  
/*Program Snippet 3 with do-while loop*/
i = 0;
do
{
   /*statement1*/
   continue;
   /*statement2*/
   i++;
}while (i < 10);

(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

My Personal Notes arrow_drop_up
Recommended Articles
Page :