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

23rd Feb 2021, 1:51 PM
Nada Hossam
Nada Hossam - avatar
7 Respuestas
+ 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.
23rd Feb 2021, 2:45 PM
你知道規則,我也是
你知道規則,我也是 - avatar
+ 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
23rd Feb 2021, 2:01 PM
Rellot's screwdriver
Rellot's screwdriver - avatar
+ 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 ?
23rd Feb 2021, 1:54 PM
Nada Hossam
Nada Hossam - avatar
+ 1
try putting the increment statement outside of the writine for clearance
23rd Feb 2021, 1:58 PM
bernborgess
bernborgess - avatar
+ 1
Can you add a link to your code? it is easier to test 😀
23rd Feb 2021, 2:17 PM
bernborgess
bernborgess - avatar
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 😅
23rd Feb 2021, 2:16 PM
Nada Hossam
Nada Hossam - avatar
0
CarrieForle Thanks alot
23rd Feb 2021, 2:58 PM
Nada Hossam
Nada Hossam - avatar