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

Offline mechanic

The follwoing program fragment for (i = 1; i < 5; ++i)
« on: March 07, 2017, 02:46:15 PM »
Advertisement
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.


Engineering Forum

The follwoing program fragment for (i = 1; i < 5; ++i)
« on: March 07, 2017, 02:46:15 PM »