IndiaBIX.com
Arithmetic Aptitude Data Interpretation
Logical Reasoning Verbal Reasoning Non Verbal Reasoning
General Knowledge
Sudoku Number puzzles Missing letters puzzles Logical puzzles Playing cards puzzles Clock puzzles
C Programming C# Programming Java Programming
Networking Database Questions Computer Science Basic Electronics Digital Electronics Electronic Devices Circuit Simulation Electrical Enigneering Engineering Mechanics Technical Drawing
Placement Papers Group Disucssion HR Interview Technical Interview Body Language
Aptitude Test Verbal Ability Test Verbal Reasoning Test Logical Reasoning Test C Programming Test Java Programming Test Data Interpretation Test General Knowledge Test
Data Structures Operating Systems Networking DATABASE Database Basics SQL Server Basics SQL Server Advanced SQL Server 2008 JAVA Core Java Java Basics Advanced Java UNIX Unix File Management Unix Memory Management Unix Process Managemnt C Interview Questions The C Language Basics .NET Interview Questions .NET Framework ADO.NET ASP.NET Software Testing

C Programming - Control Instructions - Discussion

@ : Home > C Programming > Control Instructions > General Questions - Discussion

1. 

How many times "IndiaBIX" is get printed?

#include<stdio.h>
int main()
{
    int x;
    for(x=-1; x<=10; x++)
    {
        if(x < 5)
            continue;
        else
            break;
        printf("IndiaBIX");
    }
    return 0;
}

[A]. Infinite times[B]. 11 times
[C]. 0 times[D]. 10 times

Answer: Option B

Explanation:

No answer description available for this question.


Srinivasa.S said: (Sun, Aug 22, 2010 03:26:20 AM)    
 
The condition x<5 is true until x=5, so the true block executed. The code after the continue statement(including printf("IndiaBIX");) will not executed and go to increment step(x++). Again the loop is continued.

When x=5, then else block executed, it has break statement, So loop is terminated.

Here the control never go to printf("IndiaBIX"); statement.

Amit said: (Sat, Sep 4, 2010 02:36:43 PM)    
 
The continue statement transfers the control to the next iteration in the loop (increment step).

Sandeep Kumar Singh said: (Tue, Sep 21, 2010 02:59:16 PM)    
 
The first condition is x<5, that's why loop will continue and keep incrementing value of x until x=5.

When x=5 then condition will go to else part and since break statement is there it will come out of loop.

So, it is not going to print "IndiaBIX".

Manya said: (Sun, Sep 26, 2010 03:40:37 PM)    
 
Thank you Sandeep.

Himani said: (Thu, Oct 14, 2010 08:48:05 AM)    
 
Thanks all of you. You all have cleared my doubt.

Vignatha said: (Wed, Nov 24, 2010 03:17:44 AM)    
 
Ya after the continue and break stmts nxt part o code z nt xcuted n goes to iteration, for that der z no output.

Dhivakar said: (Thu, Nov 25, 2010 12:27:01 AM)    
 
Untill x<5 the 'if' part gets executed,which contains the 'continue' statement and it simply transfers the control to the begining of the loop iteratively for 6 times....


and now x=5 the control passes to the else part which contains the 'break' statement before printf and hence the loop gets terminated before printing "indiabix"

Neha Singla said: (Fri, Nov 26, 2010 12:54:16 PM)    
 
The value of x is nt declared before the for loop, so it will not enter the loop and program will exit....

Pandu said: (Sat, Nov 27, 2010 07:04:08 AM)    
 
It prints 0 times because
unit x<5 the 'if' part gets executed,which contains the 'continue' statement and it simply transfers the control to the begining of the loop iteratively for 6 times....

Karthi said: (Sat, Dec 11, 2010 12:19:15 PM)    
 
The continue statement transfers the control to the next iteration in the loop

Vignesh said: (Thu, Dec 16, 2010 04:10:25 AM)    
 
Thanks Srinivasa.

Sweety said: (Fri, Dec 24, 2010 11:38:49 PM)    
 
The statement cannot executed the statement of x so the process of IndianBIX executed the statement executed 0times.

Sanjeev Kumar said: (Tue, Jan 11, 2011 08:15:31 AM)    
 
Basically x is initialized with -1. As x<5 (since x is -1) it will came with continue statement.

Continue means "stop the current iteration and go to the next iteration". So x becomes 0 now. This will be happened until x becomes 5. Now if x=5, it will enter the else part where it encounters break statement, as a result it will come out of for loop. As a result it will not go to printf statement. So IndiaBIX will be printed 0 times.

Owais Dar said: (Sat, Jan 15, 2011 05:32:17 PM)    
 
The value of x starts from -1 and is incremented everytime till x<5. becux the continue statement sends the control back to increment process. And once the value of x reachs 5 it executes else part, which is break statement, break statement terminates loop. This means the control will never encounter printf statement. Hence no 'IndiaBix' will be printed.

Ashu said: (Sun, Jan 16, 2011 12:31:46 PM)    
 
Till x is < 5, the if condition is satisfied and continue is encountered so the loop continue execution without executing the following statements. and when the value of x becomes 5, break is encountered and the control is transferred outside the loop. So 'IndiaBix' will not be printed even once.

Ajeshbabu said: (Thu, Jan 20, 2011 04:35:00 AM)    
 
If x is <5 ,if condition will executed, other 6 then loop process is terminated, then return 0 will occur,then final result get 0 times loop occur

Varsha said: (Thu, Feb 3, 2011 03:59:31 AM)    
 
I agree with Sanjeev kumar, thanks.

S.Sivaraj said: (Mon, Feb 21, 2011 07:07:49 AM)    
 
Yes I agree above this answer.

Prasanth Reddy.D said: (Sun, Feb 27, 2011 08:24:22 PM)    
 
Since x is an integer it has a range from -32768 to +32767.Here x value is -1.x checks the condition x<=10 and enters into for loop and then checks that x<5.since it is true continue; statement executes and since no stmt's are there in if condition, it exits from if loop.

Then x gets incremented and goes as 0,1,2,3,4.It continues as above upto x=4.

when x=5, it goes to else condition and executes the stmt break;
finally coming out of the else condition and x gets incremented to 5,6,7,8,9,10.
Thus by not printing IndiaBIX.

Ramnayan said: (Wed, Mar 9, 2011 05:18:32 AM)    
 
Here for loop executes 06 times when control enters to loop untill i<5 continue keyword is executeddue to which it skips all the code below the continue regain increment the 'i' when i just reach the 5 else is executed and break keyword through the control just outside the loop in this way not printf statement is executed.

Dileep said: (Thu, Mar 24, 2011 02:07:35 AM)    
 
Thanks to all of you.

Bhargavi said: (Sun, Mar 27, 2011 08:58:59 AM)    
 
Since we use break statement it automatically comes out of the else loop, no matter whether it satisfies if condition or not,

Sandip K Vaghasiya said: (Tue, Apr 5, 2011 06:56:01 AM)    
 
Here look at the program x is < 5, the if condition is satisfied and continue is encountered so the loop continue execution without executing the following statements. and when the value of x becomes 5, break is encountered and the control is transferred outside the loop. So 'IndiaBix' will not be printed even once.

Bandita said: (Fri, Apr 15, 2011 05:36:39 AM)    
 
Thnks Srinivas and sandeep

Basant Kumar Soni said: (Sat, Apr 16, 2011 09:08:17 AM)    
 
When the loop is start from -1 to 10 ,firstly check the if condition and follow the continue statement and from -1 to 5 condition is satisfied ,then 6 condition is satisfied and else statement go to break and terminate the loop
so that nothing will be print

Manish Niitian said: (Wed, May 4, 2011 03:07:16 AM)    
 
First you know that how to work Break and Continue statement :.

If you use 'continue' statement then that after particular condition loop will be continue in same loop and another break statement, if you use 'break' statement then terminate of that loop and go to out of loop and program will be exit.

So in this program, println ("IndiaBix") ; is used after break statement so this program is terminated. So no display any output.

Sarasa said: (Fri, May 20, 2011 10:03:29 AM)    
 
The value of X is -1 so again and again to execute the loop to increase the value in X is minus value so infinte times to execute the loop.

Ajeet said: (Wed, May 25, 2011 08:18:32 PM)    
 
Thanks to everyone.

Rohit said: (Sun, Jun 5, 2011 05:48:17 AM)    
 
Here look at the program x is < 5, the if condition is satisfied and continue is encountered so the loop continue execution without executing the following statements. and when the value of x becomes 5, break is encountered and the control is transferred outside the loop. So 'IndiaBix' will not be printed even once.so that the ans c is rite

Srikanth said: (Sun, Jun 26, 2011 05:20:05 AM)    
 
Good answer srinivasa.

Rajan said: (Thu, Jun 30, 2011 06:22:13 AM)    
 
Continue is for break current iteration. So that it gets increments and avoids the further steps and break is for break current loop. Therefore the loop is terminated.

Vaibhav said: (Tue, Jul 5, 2011 07:41:58 AM)    
 
for (x<5) five times the control will go t starting of loop due to continue. And after for the else condition the break occurs so control will go out of loop so there wont be any printing

Geethapriya V said: (Thu, Jul 7, 2011 11:14:35 PM)    
 
if(x<5) this condition is true then continue keyword go to next iteration of for loop so loop is execute till (-1 to 4)6th iteration . In 7th iteration x=5 so if the condition(x<5) is false then the break keyword is executed (i.e) break keyword is used to jump out of the for loop . The result is 0 times.

Mahesh said: (Thu, Jul 14, 2011 04:45:03 AM)    
 
Thank you Srinivasa. S.

P.Vijayan said: (Sat, Jul 16, 2011 08:40:17 PM)    
 
continue: go back the control to starting of the loop
break: terminate the execution of the loop

if(i<5) that the values are (-1,1,2,3,4) then control back to loop
else tat is i=5 then terminate the execution

So nothing to be printed.

Kvamshavardhanreddy said: (Fri, Jul 29, 2011 10:55:17 PM)    
 
Giving that if x<5 after that we used continue , it means it performs operation from next line it self after that there is a break statement when compiler performs break it it is out of loop so INDIABIX is not printed.

Sayali said: (Mon, Aug 1, 2011 08:16:57 PM)    
 
continue will transfer control back to loop statement for i = -1 to 4 since it satisfies condition if (i<5), for i=5 it will satisfy condition in the else part i.e.(!(i<5)) control will go to break statement and break statement will stop executing loop and will come out of loop and will not print indiabix

Narmada said: (Tue, Aug 9, 2011 03:53:22 PM)    
 
Thank you sayali.

Yuva said: (Sun, Sep 18, 2011 03:16:19 PM)    
 
I agree with sanjeev kumar answer.

Amrita Roy. said: (Sun, Sep 18, 2011 07:14:38 PM)    
 
I agree with Sandeep.

Soumya said: (Thu, Oct 13, 2011 10:58:15 AM)    
 
Thnks to sandeep. Its correct.

Raju Naidu said: (Mon, Oct 31, 2011 05:09:55 PM)    
 
Hai,

The keyword 'continue' is used to skip the some statements and continuing the current process. In our programm till the x=5 it continuing the process once it's reached to 5 if condition getting false so else block will be execute but in else block we had break statement, so it breaks the loop and it will never go to print the indiabix so answer is 0 times.

Vadivelan said: (Sun, Nov 13, 2011 10:24:47 AM)    
 
Thanks Friends

Shweta said: (Mon, Nov 14, 2011 11:34:37 PM)    
 
Thanks fellas.

Actually I missed to notice that 'printf' is within 'for loop', and made mistake.

Purushottam Kumar said: (Fri, Dec 2, 2011 12:41:11 PM)    
 
Here inside the program x is < 5, the "if" condition is true and continue is encountered so the loop continue inside 'for' execution without executing the following statements. and when the value of x becomes 5, 'break' is executed and the 'for' loop will be terminated , So 'IndiaBix' will not be printed even once because 'printf' will never executed.

Prajith&Amp;Ratnaji said: (Thu, Dec 8, 2011 10:06:39 AM)    
 
Thank you very much for clearing our doubt.

Vivek said: (Mon, Dec 26, 2011 08:23:16 PM)    
 
No output will be there for this code.

Dkboss said: (Thu, Dec 29, 2011 08:02:33 AM)    
 
This will printed one time ; please check your sequence and then discuss.

Disha said: (Wed, Jan 18, 2012 06:39:04 PM)    
 
Thanks to sandeep.

Anand Kumar said: (Fri, Feb 10, 2012 12:45:45 PM)    
 
Thanks you for all...........

Write your comments here:
Name *:     Email:


© 2008-2011 by IndiaBIX™ Technologies. All Rights Reserved | Copyright | Terms of Use & Privacy Policy

Advertise     Contact us: info@indiabix.com     Follow us on twitter!