Previous | Home | Next |
Say We have print Sudhir Yadav 10 times then we need to write printf("Sudhir Yadav"); ten times. To avoid this have a for loop.
Here in this we pass first initialize value from where for loop is started .The second is conditions. If this condition is true then loop body will execute else the next statement after loop will execute. Thread is increment or decrements of initialized values value.
/* Syntax of for loop */ for(initialization ;conditions, increment or decrements ) { //body of for loop }
Here in this we pass first initialize value from where for loop is started .The second is conditions. If this condition is true then loop body will execute else the next statement after loop will execute. Thread is increment or decrements of initialized values value.
The flow of for loop is firs initialize then execute loop body then increment or decrements the value then check conditions then if condition is true then again body will execute and increment or decrements the values again. Do this until condition is.
/* print your own name n times */ #include<stdio.h> #include<conio.h> void main() { int i,n; clrscr(); printf("enter a number"); scanf("%d",&n); for(i=1;i<=10;i++) printf("\nSudhir Yadav"); getch(); }
Enter a number 10
Sudhir Yadav Sudhir Yadav Sudhir Yadav Sudhir Yadav Sudhir Yadav Sudhir Yadav Sudhir Yadav Sudhir Yadav Sudhir Yadav Sudhir YadavPrevious | Home | Next |