+ 6
Isn't this answer wrong?
int x=0; while (x <5) { x = x++; } this will cause an infinite loop. but the quiz answer mentions this as finite loop. How to get this corrected?
12 ответов
+ 16
It is an infinite loop. The answer to the question is wrong
+ 8
Ok follow Filip's answer xd
+ 7
Every time I encounter this question, my conscience kills me.
+ 7
x = x++ is similar to:
var tmp = x;
x++;
x = tmp;
So yeah, infinite loop...
Source: http://stackoverflow.com/a/226019
+ 7
yes this is an infinite loop only but if u encounter this question in Java then the quiz answer would also be infinite loop only....I lost a match due to this , I thought in Java also they would have done wrong so I gave that it's not infinite and came to know that here the answer is the correct one only
+ 6
Yeah I'm probably wrong because I don't know C++...
+ 4
just run this code and see. x = x++ changes nothing about x
+ 4
@steven Look at all the answers first, including mine. You might find your answer xD
+ 1
No, it is finite.
First loop, x = 1
......
Fifth loop, x = 5
The while loop stops.
(This thing is wrong)
+ 1
Why is it infinite? x = x++ uses the value of x and then increments it meaning that x now = 1 ... if this is in fact infinite, then i also need some clarification. seems like a valid loop to me??
+ 1
@Jafca I have read the other posts but my logic keeps telling me this looks right. why is x++ not incrementing x? and if it is, then shouldnt this be finite?
EDIT
never mind, it just clicked... i can see it now.
+ 1
It is infinite . because x++ is post increment ! x=x++ is not a useful function as it is equal to x=x (post increment meaning ) and everytime the loop exits , x value is retained before it goes into the loop again i.e it doesn't get incremented outside the loop !