0

How to use continue in C.

I have this code: // Wil stop at 4 int number = 1; while(number <= 10){ if(number == 5) continue; printf("%d", number); number++ } but the code will stop at number 4 and won't continue anymore, why? I want to print from 1 to 10 skipping the number 5, why the code stops at 4? it should jump to number 6 and continue to umber 10. if I change the while for a for loop, the code will execute in the correct way, but why in while it doesn't execute in the correct way?

16th Aug 2018, 3:27 AM
Eduardo Perez Regin
Eduardo Perez Regin - avatar
2 Respuestas
+ 5
Try putting number++ at top in while loop and your code will run fine. Hope this helps ☺️☺️.
16th Aug 2018, 3:35 AM
Meet Mehta
Meet Mehta - avatar
+ 3
Because after it will skip number 5 , it will again check condition. number is still 5 and it goes on. In for loop after 5 , number is first incremented and than condition is checked.
16th Aug 2018, 3:42 AM
Meet Mehta
Meet Mehta - avatar