+ 4
break and continue
Why does this code not show "5" at the end? The "if (num == 5)" statement should make it loop till it's even with 5. I'm not getting this. Can someone assist w/this example please? Thanks. int num = 0; while (num < 20) { if (num == 5) break; Console.WriteLine(num); num++; } /* Outputs: 0 1 2 3 4 */
4 Réponses
+ 6
If you put WriteLine before the if clause, the number 5 will be shown. ;)
+ 3
when it found the num ==5 then it find break and it will stop
good luck
+ 2
Thank you Jamie and Abdurrahman. I believe I have it now.I was in the mindset of "if (num > 5)" then stop (break).
0
you break the statement num before output and it should be shows below then 20