Loop
A loop statement allows us to execute a statement or group of statements multiple times given a certain condition.
Types of Loops
1.Do-while loop
2.While loop
3.For loop
Do-while loop
Syntax:-
do
{
//statement//
}
While( …Condition… );
Ex-
#include<stdio.h>
#include<conio.h>
Void main()
{
int i=1;
do
{
printf(“%d”,i);
++i;
}
While(i<=10);
getch();
}
while loop
Syntax:-
While( …Condition… )
{
//statement//
}
Ex-
#include<stdio.h>
#include<conio.h>
Void main()
{
int i=1;
While(i<=10)
{
printf(“%d”,i);
++i;
}
getch();
}
for loop
Syntax:-
for(initialization ; Condition ; increment/decrement )
{
//statement//
}
Ex-
#include<stdio.h>
#include<conio.h>
Void main()
{
for(int i=1;i<=10;i++)
{
printf(“%d”,i);
}
getch();
}
0 Comments