- 1
#include<stdio.h> int main(){ int i; for(i=10;i++;i<15) printf("%d\n",i); }
why does this runs as an infinite loop
3 Answers
+ 1
because you don't use the for arguments as needed:
for (init; condition; inc)
so in your case:
for (i=10; i<15; ++i)
0
I very well know the format of a for loop. But what I am curious about is that why I am getting an infinite output
0
as i start with 10, and the 'for' condition is 'i++', it will be ever true: that's why you'll get an infinite loop...