[go: up one dir, main page]

0% found this document useful (0 votes)
24 views4 pages

Loop

The document explains looping statements in C, which execute a sequence of statements repeatedly until a condition is false. It details three types of loops: for loop, while loop, and do-while loop, providing their syntax and examples. Each loop type is illustrated with code snippets that print numbers from 1 to 10.

Uploaded by

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

Loop

The document explains looping statements in C, which execute a sequence of statements repeatedly until a condition is false. It details three types of loops: for loop, while loop, and do-while loop, providing their syntax and examples. Each loop type is illustrated with code snippets that print numbers from 1 to 10.

Uploaded by

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

What is Loop in C?

Looping Statements in C execute the sequence of statements many times until


the stated condition becomes false. A loop in C consists of two parts, a body of a
loop and a control statement.

For loop in C
A for loop is a more efficient loop structure in ‘C’ programming. The general
structure of for loop syntax in C is as follows:

Syntax of For Loop in C:


for (initial value; condition; incrementation or decrementation )
{
statements;
}

#include<stdio.h>
int main()
{
int number;
for(number=1;number<=10;number++) //for loop to print 1-10 numbers
{
printf("%d\n",number); //to print the number
}
return 0;
}

Output:
1
2
3
4
5
6
7
8
9
While Loop in C
A while loop is the most straightforward looping structure. While loop syntax in C
programming language is as follows:

Syntax of While Loop in C:


while (condition) {
statements;
}

#include<stdio.h>
#include<conio.h>
int main()
{
int num=1; //initializing the variable
while(num<=10) //while loop with condition
{
printf("%d\n",num);
num++; //incrementing operation
}
return 0;
}

Output:
1
2
3
4
5
6
7
8
9
10

Do-While Loop
Syntax of do while loop in C programming language is as follows:

Syntax of Do-While Loop in C:


do {
statements

} while (expression);

#include<stdio.h>
#include<conio.h>
int main()
{
int num=1; //initializing the variable
do //do-while loop
{
printf("%d\n",num);
num++; //incrementing operation
}while(num<=10);
return 0;
}

Output:
1
2
3
4
5
6
7
8
9
10

You might also like