0% found this document useful (0 votes)
2 views

loop in C

The document provides an overview of different types of loops in programming, including while loops, do-while loops, for loops, and nested for loops. Each loop type is accompanied by its syntax and examples demonstrating their usage. The document also includes sample output for nested loops.

Uploaded by

landeparth93
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

loop in C

The document provides an overview of different types of loops in programming, including while loops, do-while loops, for loops, and nested for loops. Each loop type is accompanied by its syntax and examples demonstrating their usage. The document also includes sample output for nested loops.

Uploaded by

landeparth93
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

-------------------------------------------------------------------------

Loop or iterative
-------------------------------------------------------------------------

- while loop
- do-while loop
- for loop
- nested loop

WHILE LOOP:

Syntax:
while(expression)
{
statement;
..............
..............

Example:

int n; // declaration
n = 1; // initializationo
printf("before start of the loop\n");
while(n<10)
{
printf("%d \t",n);//123456789
n++;
}

printf("\ncame out of the loop!!!");

- DO-WHILE LOOP

Syntax:
do
{
statement;
..........
..........
}
while(expression);
- FOR LOOP

Syntax:
for(initialization; expression; increment /decrement)
{
statement;
.............
}

Example:
int n ;
for(n =10; n>=20; n--)
{
printf("count : %d\n",n);
}

- NESTED FOR LOOP

Syntax:

for(initialization; condition; increment/decrement)


{
for(initialization; condition;increment/decrement)
{
statement;
..............
}
}

Example:
int i,j;
for(i = 0; i<10; i++)
{
for(j = 0; j<=i; j++)
{
printf("%c",3);
}
printf("\n");
}

Output:
@
@@
@@@
@@@@
@@@@@
@@@@@@
@@@@@@@
@@@@@@@@
@@@@@@@@@
@@@@@@@@@@

You might also like