Computer for SEE and NEB

It is a complete SEE and NEB solution for computer science. It includes Computer Fundamentals, Database (SQL), Programming in C QBASIC, CSS, JavaScript, and PHP for beginners.

Breaking

Post Top Ad

Your Ad Spot

Wednesday, August 24, 2022

Difference between for loop and while loop in C programming

 

Difference between for and while loop

 

for loop

while loop

1.    It is entry controlled loop so value is initialized with for.

1.    In this loop value must be initialized before the loop begins.

2.    It is definite loop in which user can identify how much time does loop execute.

2.    It is an indefinite loop in which user may not identify that how much time does loop execute

3.    Program becomes shorter using for loop

3.    Program becomes longer using while loop

4.  It used the keyword for

4. It used the keyword while

5.  Syntax:

for(expression1, expression2, expression3)

{

block of statements;

}

 

5. Syntax:

while(expression)

{

body of loop;

}

6. eg. # include <stdio.h>

main ( )

{

int i ;

for (i = 1; i<=100; i++)

{

printf ("%d",i);

}

6. eg. # include <stdio.h>

main ( )

{

int i;

i = 1;

while (i < = 100)

{

printf ("%d",i);

i++;

}

 

No comments:

Post a Comment

Post Top Ad

Your Ad Spot

Pages