Diff between for loop and while loop?

Answers were Sorted based on User's Feedback



Diff between for loop and while loop?..

Answer / keerthana

for loop is executed the condition is satified ..the loop
is executed. ex: n=5 ..the loop is 5 times executed..becoz
the condition is true..otherwise loop is exit.

while loop is executed the condition is true..otherwise
after one time..executed until the condition is false..

Is This Answer Correct ?    15 Yes 5 No

Diff between for loop and while loop?..

Answer / naresh lingampally

In both the loops the Out put is same.... but the compile
structure is different:

i.e..,
syn: for(i=0;i<=10;i++)
{
statement;
}

while(i<=10)
{
statement;
i++;
} .

i=0; --> initialization.---{1)
i<=10;---> conditioning ---(2)
i++; ---> incrementation ---(3)


in (while) the compiler order would be
(1) .. not along with the loop
(2),(3) in the loop

but in (for) the order is (1),(2),(3) in a single statement.

NOTE: MAJOR DIFFERENCE IS WE CAN REDUCE THE LENGTH OF THE
PROGRAM (FOR) NAD IS MORE SOPHISTICATED.

Is This Answer Correct ?    4 Yes 2 No

Post New Answer

More C Interview Questions

Find the O/p of the following struct node { char *name; int num; }; int main() { struct node s1={"Harry",1331}; struct node s2=s1; if(s1==s2) printf("Same"); else printf("Diff"); }

1 Answers  


what is the use of macro program

1 Answers   TCS,


how we do lcm of two no using c simple if while or for statement

1 Answers  


Explain what are header files and explain what are its uses in c programming?

0 Answers  


How reliable are floating-point comparisons?

0 Answers  






Explain how can I convert a string to a number?

0 Answers  


How do you print an address?

0 Answers   TCS,


What does calloc stand for?

0 Answers  


progrem to generate the following series 1 12 123 1234 12345

6 Answers   HCL, Wipro,


#include<stdio.h> void main() { int a [5]; for (i=0; i<=4; i++) printf(ā€œ%dā€ ,a[i]); }

8 Answers  


#include<stdio.h> #include<conio.h> void main() { int m=0111,n=20; printf("%d%d\n",m,n); getch(); }

1 Answers  


why i join syntel?

23 Answers   ABC, Syntel, TCS,


Categories