Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

while(0=0) evaluates to false

b=10;
while(a=b) {
  b--;
  if(b==-10)break;
}

B goes from 10 to -10. In my world, the while-statement, a=b, should always be true (since the assigment always "goes well"). That is not the case. When the loop stops, b will have a value of 0.

In my world, it should pass 0 and go all the way to -10, when the if-statement kicks in.

Have I misunderstood something major? (Code tested in IE8 and Adobe Acrobat)

like image 604
o-o Avatar asked Jun 11 '10 15:06

o-o


1 Answers

(0 = 0) == 0 == false
like image 121
Jonathon Faust Avatar answered Sep 20 '22 14:09

Jonathon Faust