C# postfix in do while loop šŸ¤•šŸ¤• Help plz! | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
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 Respostas
+ 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