+ 2
C# While Loop Question
Ok guys and gals, for some reason my brain is not processing this simple while loop. Can someone help me with why I'm getting an output of 5? static void Main(string[] args) { int i = 0; int a = 92751; while (a != 0){ a /= 10; i++; } Console.Write(i);
2 ответов
+ 5
Yap. The Out put is 5,
First 92751 != 0. So it gets divided by 10. i=1;
Next 9275 != 0. So it gets divided by 10. i=2;
Next 927 != 0. So it gets divided by 10. i=3;
Next 92 != 0. So it gets divided by 10. i=4;
Next 9 != 0. So it gets divided by 10. i=5;
Next 0 = 0. Then Loop will exit
Finally i = 5
0
Ah! Thanks Yasiru!