While Loop
Main concept
while(condition)
{
statement;
}
Do While Loop
Main concept
do
{
statement;
}
while(condition);
AS LONG AS THE CONDITION IS VALID, THE STATEMENT, INSIDE THE WHILE (OR DO WHILE) LOOP, WILL KEEP ON RUNNING, NO MATTER WHAT THE STATEMENT IS
Print even numbers from 1 to 100.
#include<conio.h>
#include<stdio.h>
void main()
{
clrscr();
int a=2;
while(a<=100)
{
printf(“%d\t”,a);
a=a+2;
}
getch();
}
Print “THIS IS A TEXT” n times using do while.
#include<conio.h>
#include<stdio.h>
void main()
{
clrscr();
int a=1,n;
scanf(“%d”,&n);
do
{
printf(“THIS IS A TEXT\n”);
}
while(a<=n);
getch();
}