Register
 

Free CSC Scholarship support for 2018-19

Engineering, Computer, Scholarship and SEO Support Forum




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

Offline mechanic

  • Engineer
  • Hero Engineer
  • *****
  • Posts: 3035
    • View Profile
    • Engineering Forum
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, Computer, Scholarship and SEO Support Forum

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