Using Constructs- III

 Loop Constructs

While Loop 

A While loop block of statements the condition is evaluated first and if it is True the loop body is executed. After execution of the loop body the condition in the while statement is evaluated again.This repeats until the condition becomes False. 

Syntax:

while (argument) 
{
    // statements inside the body of the loop 
}


Do...while Loop

 The do...while loop construct like the while loop construct is used in situations where operations is to be performed is not known, and is dependent on a condition, which changes within the loop body. Also, iterations are to be performed until the specified loop condition becomes False.

Syntax:  
do
{
   // statements inside the body of the loop
}
while (arguments);

It differs from the while loop always remember !!!

 

Example 1: Accept any number and print total number of digits Using While loop




Example 2: Print number series Using While loop

 



Example 3: Reverse of a number Using While loop
 


Example 4: Program to do addition of numbers until the user enters null value or zero using Do...while



Comments