What are loops?
A Loop executes the sequence of statements many times until the stated condition becomes false.
* A loop consists of two parts, a body of a loop and a control statement
C programming language provide three types of loop structure
*While loop
*Do_while loop
*For loop
While loop:In while loop, a condition is evaluated before processing a body of the loop. If a condition is true then and only then the body of a loop is executed. After the body of a loop is executed then control again goes back at the beginning, and the condition is checked if it is true, the same process is executed until the condition becomes false. Once the condition becomes false, the control goes out of the loop.
syntax for while loop
while (condition) {
statements;
}
Do_while loop:In the do-while loop, the body of a loop is always executed at least once. After the body is executed, then it checks the condition. If the condition is true, then it will again execute the body of a loop otherwise control is transferred out of the loop
syntax for Do_while loop
do {
statements
} while (expression);
For loop:
* The initial value of the for loop is performed only once.
* The condition is a Boolean expression that tests and compares the counter to a fixed value after each iteration, stopping the for loop when false is returned.
* The incrementation/decrementation increases (or decreases) the counter by a set value.
syntax for For loop
for (initial value; condition; incrementation or decrementation )
{
statements;
}