The follwoing program fragment for (i = 1; i < 5; ++i)

  • 0 replies
  • 584 views
*

Offline mechanic

  • *****
  • 2513
    • View Profile
    • Engineering Forum
The follwoing program fragment for (i = 1; i < 5; ++i)
« on: March 07, 2017, 02:46:15 PM »
Question: The follwoing program fragment

for (i = 1; i < 5; ++i)
if (i ==3) continue;
else printf("%d ", i);


Results in the printing of?

Options are:


A. 1 2 4 5
B. 1 2 4
C. 2 4 5
D. None of the above

Correct answer is:

B. 1 2 4

Explanation


The use of continue statement forces the execution to skip the remainder of the current pass over the loop and initiates the next. If 'i' is 3, printf statement will be skipped.
hence the answer is B.