C while Loop

C while loop Syntax:
while(condition)
{
statement1;
statement2;
statement3;
increment/decrement statement;
}

  • When we are working while loop always prechecking process will be occurred.
  • Prechecking process means before execution of statement block conditional part will be executed.
  • While loop will be repeated in clock direction.

Example1: Print numbers from 1 to 10.

void main()
{
int i;
i=1;
while(i<=10) { printf("%d",i); i++; } getch(); }

Example2:Print numbers from 10 to 1

void main()
{
int i;
i=10;
while(i>1)
{
printf(“%d”,i);
i=i-1;
}
getch();
}

Powered by k2schools