Author Topic: The follwoing program fragment for (i = 1; i < 5; ++i)  (Read 677 times)

Offline mechanic

  • Engineer
  • Hero Engineer
  • *****
  • Posts: 2594
    • View Profile
    • Engineering Forum
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.