Loops are generally used to repeat a block iteratively for a fixed number of times.
Syntax of while is:
For a loop the three main expression are: initialization, condition and increment/decrement operation.
In while loop, initialization is done outside the loop and the increment/decrement operation is done inside the loop. Let us understand more clearly from the below example:
// To find the sum of ‘n’ numbers
cout<<”\n Enter n:”;
int i=0; // Initialization
while(i<n) // Condition
sum=sum + i; // Statement
i++; //Increment operation
The while loop is repeated till the condition becomes False.