0
C# postfix in do while loop đ€đ€ Help plz!
int i =1 , j=5 ; do { Console.WriteLine(i=i++*j); }while (i<=10); I am really confused with this question why the output equals 5,25 not 5,30 ?! Why it doesnât increment i ? https://code.sololearn.com/c27w2ZT26HM4/?ref=app
7 Answers
+ 4
When i = 1
i = i++ * j
-> i = 1 * 5
-> 5
Is i <= 10? Yes, continue.
i = i++ * j
-> i = 5 * 5
-> 25
Is i <= 10? No, loop ends.
+ 2
Nada Hossam ah yeah, but you were only doing with i variable as I observed your code, you didn't do the same thing in j to get 6 * 5.
sooo, here's the solution, which I fixed it by putting an increment to j.
https://code.sololearn.com/cjpMQQTAi9jr/?ref=app
+ 1
but why it doesnât increment i to be 6 * 5 ?? as a postfix it wonât change in the same line and then it should be incremented by 1 in the next line , isnât true ?
+ 1
try putting the increment statement outside of the writine for clearance
+ 1
Can you add a link to your code? it is easier to test đ
0
Coding Kitty[exams] I am really gratful to you đž but I guess you didnât understand what I am confused with , the above question itâs answer is 5,25 and I canât understand why .
I am a beginner đ
0
CarrieForle
Thanks alot