#include<stdio.h> int main(){ int i; for(i=10;i++;i<15) printf("%d\n",i); } | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 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

9th Feb 2021, 5:40 PM
Utsav Sharma
Utsav Sharma - avatar
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)
9th Feb 2021, 5:42 PM
visph
visph - avatar
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
10th Feb 2021, 3:34 AM
Utsav Sharma
Utsav Sharma - avatar
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...
10th Feb 2021, 3:36 AM
visph
visph - avatar