C while loop

  while loop

The while loop  is to be used in the scenario where we don't know the number of iterations in advance. The block of statements is executed in the while loop until the condition specified in the while loop is satisfied. It is also called a pre-tested loop.The while loop is also known as Entry control looping statement

Syntax 

variable initialization

while(condition)

{

block of statements;

variable increment or decrement;

}

Example
 

To print table of given a number.

    #include<stdio.h>
    #include<conio.h>
    void main(){    
    int i=1,number=0;    
    printf("\n Enter an integer: ");    
    scanf("%d",&number);    
    while(i<=10){    
    printf("\n %d * %d = %d ",number,i,(number*i));    
    i++;    
    }     
    getch();
    }   

Output 

 





No comments:

Post a Comment