#1508 js: assignment and comparison in one expression

dsav Tue 26 Apr 2011

Please, consider the following code:

Int[] list := [1, 2, 3, 4]
Int? t := null
while (null != (t = list.find { it == 2 })) {
  echo(t)
  list.remove(t)
}

In Java, it works as intended (prints 2 and finishes). In JS, it prints true in an infinite loop. It's because in JavaScript the while loop looks like this:

while (t = <list.find> != null) {
  ...
}

(parenthesis omitted).

andy Tue 26 Apr 2011

Promoted to ticket #1508 and assigned to andy

Login or Signup to reply.