![types of looping and computer software](https://bcisnotes.com/firstsemester/wp-content/uploads/2019/12/types-of-looping-and-computer-software-1.jpg)
Types of Looping and Function
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.
- For loop
- while loop
- Do…while loop
- Nested loop
Types of Looping
For loop
For loop is the most commonly used statement in C. This loop consist of three expressions, the issue of the first expression to initialize the index value, the second expressions check the condition and 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.
- Libary function/builting function.
- The user defines a function.
A function return with function-declaration name of the function return type, parameter, and block of statements.
The advantages of functions are below.
- Code Re-usability.
- develop an application in module format.
- Easy to debug the program.
- Code optimization, no need to write a lot of code.
- The code is easier to read.
- Program testing becomes easy.
- compilation time gets smaller.
- The program can be developed in a short period of time.
- There is no chance for code duplication.
Syntax:
Function declaration;
return_type function_Name ()
{
statement 1;
statement 2;
return;
}
you may also like Initializing arrays
Leave a Reply