The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
x
0 votes
113 views

What is the output of the following program?

int main()
{
    int i=0;
    do {
        if (i >=5)  {
            i+=2;
            printf("%d \n", i);
            break;
        }
        else {
         printf("%d \n", ++i);   
         continue;
        }
    } while (i<7);
}    
asked in Algorithms by Veteran (96.1k points) | 113 views

1 Answer

+2 votes

It will print 1,2,3,4,5,7

It is a preincrement of i . So every time it  first increment and then assign the value and print

So, upto 5 it will print

Then it will go to ' if ' part of program 

There i value becomes 7 , breaks the loop and exit

answered by Veteran (111k points)
edited by
+1
Here continue jumps to condition i.e while(i<7)
+1
continue skips some code

If there is some code after continue it just go to the next iteration of the loop without looking at the codes

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
49,541 questions
54,083 answers
187,208 comments
70,992 users