0
Why am I getting output 5,5
This is actually a question from an app my college informed the students to install and answer the tests The code is actually correct This is how it was exactly in the question Can anyone explain it's logic to me https://code.sololearn.com/cg3bO5rWA00q/?ref=app
4 Answers
+ 4
change the comma to && and you will nolonger have an error but my question is to why you are using two simple arguments as 4 is where the while is going to stop...
Answer: 4,4
https://code.sololearn.com/czqZQFcPYVfK/?ref=app
+ 3
If you run this code in Code Playground you will get a warning, which points out that you have used comma operator with the `while` loop condition. Simply put, comma operator evaluates the left hand side operand then discard the result, it then continue by evaluating the right hand operand and use it instead. so first, `i < 4` is evaluated, but is discarded, ignored; thus `j < 5` is then used as the condition for the `while` loop. Due to this, both variable <i> and <j> gets incremented the same number of times, and end up with the same value.
Hth, cmiiw
(Edited)
0
BroFar
That's a Multiple choice question in a test and the code is the exact same of that in the test
Not something i did
0
Ipang
Yeah i understand i<4 is discarded but why am i getting an output of 5 when j<5
Shouldn't the loop stop once the condition isn't satisfied