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();
}
More Stories
Notice: Trying to access array offset on value of type bool in /hermes/bosnacweb05/bosnacweb05bi/b2282/ipg.jbbuidtech37209/timecomputers/wp-content/themes/enternews/inc/template-functions.php on line 601
C tutorial in telugu about Strings Part 36
Notice: Trying to access array offset on value of type bool in /hermes/bosnacweb05/bosnacweb05bi/b2282/ipg.jbbuidtech37209/timecomputers/wp-content/themes/enternews/inc/template-functions.php on line 601
C language tutorial in telugu free download Part 35
Notice: Trying to access array offset on value of type bool in /hermes/bosnacweb05/bosnacweb05bi/b2282/ipg.jbbuidtech37209/timecomputers/wp-content/themes/enternews/inc/template-functions.php on line 601
How to learn c programming in telugu Strings example2 part 34