Published by: Zaya
Published date: 17 Jun 2021
Looping is the repetition of any statement until the given condition is satisfied. Repetitive operation is done by a loop control statement. There are methods for generating the repetition of certain parts of the program. There are four types of looping statements.
Types of Looping
For loop
For loop is the most commonly used statement in C. This loop consists of three expressions, the issue of the first expression to initialize the index value, the second expressions check the condition and the third repressions change the index value as increment, decrement.
Syntax:
for(initialization; condition; increment, decrement)
{
statement 1;
statement 2;
}
While loop
While loop is the looping statement which first checks whether the initial condition is true or false. Finding conditions to be true it was will enter the loop and execute the statement.
Syntax:
initialization;
while( condition )
{
statement 1;
statement 2;
increment/decrement;
}
Do...while loop
Do...while loop is the looping statement of C program. It inters loop at least one and checks whether the given condition is true or false.
Syntax:
initialization;
do
{
statement 1;
statement 2;
increment/decrement;
}
while( condition );
Nested loop
A nested loop is a loop within a loop, an inner loop within the body of an outer one. How this works is that the first pass of the outer loop triggers the inner loop, which executes to completion. Then the second pass of the outer loop triggers the inner loop again. This repeats until the outer loop finishes.
Function
The function is the group of statements that together perform a group of a task. The function is the block or part of a program. There are two types of functions.
The advantages of functions are below.
Syntax:
Function declaration;
return_type function_Name ()
{
statement 1;
statement 2;
return;
}