while(0=0) evaluates to false

Posted by paque on Stack Overflow See other posts from Stack Overflow or by paque
Published on 2010-06-11T15:04:13Z Indexed on 2010/06/11 15:12 UTC
Read the original article Hit count: 177

Filed under:
|
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)

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about operators