0

what is the different between for () ; and for () {}

https://www.sololearn.com/post/347212/?ref=app The Ans is 4 But my question is what is the different between For ( i=1;i<4;i++); prinf (" %d",i); And For (i=1;i<4,i++) { printf ("%d ",i); }

22nd Apr 2020, 9:06 PM
Mohamad Alkaleeh
4 Answers
+ 2
You can run in playground and see it.. Using semicolon after for statement cause loop terminate there, not let go out for statement.. So next printf not comes under for loop.. It is same as for(i=1;i<4;i++){} equal to for(i=1;i<4;i++); After coming out printf("%d", i) ; executed so ones and i=4 then. but for(i=1;i<4;i++) { printf("%d", i) ; //this prints i 3 times. 1,2,3 }
22nd Apr 2020, 9:18 PM
Jayakrishna 🇼🇳
+ 2
3<4 is true so prints 3. But next is 4, when 4<4 is false. And Loop terminated, comes out. So now i=4 outside loop..
22nd Apr 2020, 9:31 PM
Jayakrishna 🇼🇳
0
Thanks I tried and saw the result but i didn't understand how i became equal to 4 in the first example i =1<4 2<4 3<4 And print i equal to 3
22nd Apr 2020, 9:27 PM
Mohamad Alkaleeh
0
Okay, thank you👍
22nd Apr 2020, 9:33 PM
Mohamad Alkaleeh