0
while loop for c sharp
So this equals 2,3,4,5,6 but why does it not stop before 6? why does ++num stop at 5? its confusing me int num = 1; while(num++ < 6) Console.WriteLine(num); } } }
3 Réponses
+ 6
Before we start discuss about this code you have to know difference of prefix and postfix
In here when it's num++<6
At first iteration check 1<6
But print 2
Why it's happened? because it is prefix ..
Prefix means first store then increase..that why when it checked num++<6 num don't increase but after that num increase and print 2
Loop run continuously untill num =6
At last iteration of 5th loop check
5<6 and print 6
After that it will check 6<6 and loop end..
0
I get the store of a number then to increase it. But why does one loop until its 5 and the other until its 6? Its going over my head. -_-
0
ok so i think i got it. so one gives 5 outputs and the other gives 6. so i got it better. but why specifically does it do that. why does it have to be a certain amount of outputs