+ 4

[Solved]Why isn't it giving me the same result.

There are two codes, one in a comment and one is not .I was expecting to get the same output but it didn't happen😑. Because one is in the short form of one .Can you please check the code and tell me why?🤔.When you run one then you put it in a comment and run the second.Thank you https://code.sololearn.com/cO9kof7d34Dz/?ref=app

17th Mar 2021, 8:06 PM
!Derrickee
!Derrickee - avatar
4 ответов
+ 2
<Derrickee/> in first case you (post)increment num: that's fine for the condition, but you output the incremented num... in second case you increment num at end of loop iteration (after output it)... you rather would do: while (num <= 10) { Console.WriteLine (num++); }
17th Mar 2021, 8:11 PM
visph
visph - avatar
+ 3
Thanks guys😁.The should have notify us in the course .They just said the shorter much.
17th Mar 2021, 8:14 PM
!Derrickee
!Derrickee - avatar
+ 1
while (num++ <= 10) { here in post increament , first it will check value num<=10, then num=num+1; happens.. So 1st it will be like 0<=10 , after this num=1, so while printing, num=1 But in 2nd loop, you are first printing value then after incrementing... <Derrickee/> in post increment(num++) first value is used first then after it increments. in preincrement (++num), first its value incremented then its new value used in statement.. Hope it helps...
17th Mar 2021, 8:13 PM
Jayakrishna 🇮🇳
+ 1
<Derrickee/> its here mentioned in prefix, post fix topic https://www.sololearn.com/learning/2590/
17th Mar 2021, 8:19 PM
Jayakrishna 🇮🇳