C Programming For Loop
C Programming For Loop
C Programming Loops
Loops cause program to execute the certain block of code repeatedly until test condition is false. Loops are used
in performing repetitive task in programming. Consider these scenarios:
You want to execute some code/s certain number of times depending upon input from user.
These types of task can be solved in programming using loops.
There are 3 types of loops in C programming:
1. for loop
2. while loop
3. do...while loop
Output
Enter the value of n.
19
Sum=190
In this program, the user is asked to enter the value of n. Suppose you entered 19 then, count is initialized to 1
at first. Then, the test expression in the for loop,i.e., (count<= n) becomes true. So, the code in the body of
for loop is executed which makes sum to 1. Then, the expression ++count is executed and again the test
expression is checked, which becomes true. Again, the body of for loop is executed which makes sum to 3 and
this process continues. When count is 20, the test condition becomes false and the for loop is terminated .
Note: Initial, test and update expressions are separated by semicolon(;).