When we want to perform a similar task multiple times, we can use the concept of loops.
Basically there are three types of loops in C language.
1. For loop
2. While loop
3. Do - While loop
We can also implement loops inside other loops which is known as nested loops concept.
For Loop :
The syntax for the "for" loop is
for ( initialization ; condition ; increment / decrement / changes )
{
// Statements to be executed repeatedly
}
The for loop is executed repeatedly until the condition becomes false.
While Loop :
The syntax for the "while" loop is
while( condition )
{
// Statements to be executed repeatedly
}
The while loop is executed repeatedly until the condition becomes false.
Do - While Loop :
The syntax for the "do - while" loop is
do
{
// Statements to be executed repeatedly
}
while( condition );
The do - while loop is executed repeatedly until the condition becomes false. The do - while loop will execute the statements atleast once irrespective of the condition, whereas the for and while loops will execute the statements only if the condition is true.
Comments
Post a Comment