in C, how can we convert an infinite loop to a finite loop without repelling anything in the for loop syntax ....
#include<stdio.h> #include<conio.h> int main() { int a; a=1; a++; for( ; ; ) { a<=10; printf("%d",a); } getch(); }
Here you can use the instructions break.
break
This will exit the loop and start control under the loop body.
#include<stdio.h> #include<conio.h> int main() { int a = 0; for(;;) if ((++a) <= 10) printf("%d",a); else break; getch(); }
I think this is what you ask here ...
EDIT
int main() { int a; a=0; for(;;) { if(a>10) break; printf("%d",a); a++ } getch(); }
Make a condition inside the loop where you want to end it. Otherwise, use break or exit as statements ...
try this code:
#include<stdio.h> #include<conio.h> int main() { int a; for(a=1 ; a<=10; a++) { printf("%d",a); } getch(); }
#include<stdio.h> #include<conio.h> int main() { int a; a=1; m: for(;;) { if(a<=10) { printf("%d\n",a); a++; } if(a<10) { goto m; } } getch(); }