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 Antworten
+ 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