what is loop in c programming

Given Diagram is the flowchart to understand how looping works in programming.
Let us start learning how loop work with the help of flowchart given in the fig.
The Loop flow chart consist of two Major Parts:
i. Control Statement.
ii. The Body
i. Control Statement:
Control statements are The conditions or criteria that programmer want to implement during the execution of the loop in the Program.
ii. The Body:
The Body part are the statements or instruction that programmer want to repeate multiple times untill certain condition is met.
The flow diagram is to show number series from 1,2,3......10 using loops.
Flow diag. Explanation:
Step 1: Start the loop or program.
Step 2: Declare and initilize i=1.
     here the value of i is initilized to 1
Step 3: test i<=10
        value of i is 1 so i<=10 is true and control goes to show i statement.
after processing it shows value of i .i.e 1 on screen.
Next i=i+1 is processed, which increase the value of i by 1 hence i becomes 2 i.e i=2.
after that it again test the condition i<=10
i.e 2<=10 which is true then control goes to show i statement.
it show value 2. Next i=i+1 processed and increase the value of i by i here i become 3 i.e. i=3.
again test the condition i<=10 which is true.
The above process repeate until value of i is less or equal to 10 i.e. i<=10
when i becomes i=11 then loop will ternminate and control come out of loop.
Step 4: Stop the program execution.
• The initialization and declaration in a loop given in flow dig. is performed once, and it is never repeated.
• If the number of iterations is not mentioned in the for loop i.e. i<=10, it will continue to execute infinite times.


Disadvantage of loops in Programming.

• If the condition is not well defined in the loop then loop might lead to unexpected result.
• the control will never come out of loop or exit if the condition is always true. And due to this program run indefinnitely.


Previous Topic:-->> switch case statement in C || Next topic:-->>goto statement in C.