February 23, 2025

Telugu Tech Tuts

TimeComputers.in

C tutorial in telugu for beginners for loop Part 21

for Loop Syntax

for(initialization statement; test expression; update statement) {
code/s to be executed;
}

How for loop works in C programming?

The initialization statement is executed only once at the beginning of the for loop. Then the test expression is checked by the program. If the test expression is false, for loop is terminated. But if test expression is true then the code/s inside body of for loop is executed and then update expression is updated. This process repeats until test expression is false.

This flowchart describes the working of for loop in C programming.

Flowchart of for loop in C programming language

#include
void main(){
int n, count, sum=0;
printf(“Enter the value of n.n”);
scanf(“%d”,&n);
for(count=1;count<=n;++count) //for loop terminates if count>n
{
sum+=count; /* this statement is equivalent to sum=sum+count */
}
printf(“Sum=%d”,sum);
getch();
}