# chaining "="

Cedric Bosch
Ranch Hand
Posts: 92
3
I've found 2 question in enthuware where the answer seem a bit contradictory at first glance, so I'd like some clarification.

First this :

a, b and c take the value of 9. So it looks like when chaining "=" it goes from right to left.

Second question :

Note that boolean operators have more precedence than =. (In fact, = has least precedence of all operators.)
so, in (b2 != b1 = !b2) first b2 != b1 is evaluated which returns a value 'false'. So the expression becomes false = !b2. And this is illegal because false is a value and not a variable!

Had it been something like (b2 = b1 != b2) then it is valid because it will boil down to : b2 = false.
Because all an if() needs is a boolean, now b1 != b2 returns false which is a boolean and as b2 = false is an expression and every expression has a return value (which is actually the Left Hand Side of the expression). Here, it returns false, which is again a boolean.

Note that return value of expression : i = 10 , where i is an int, is 10 (an int).

I'm not sure what I'm missing. Do they mean that the presence of the "!" operator make it so it's going left to right ?

Bear Bibeault
Author and ninkuma
Marshal
Posts: 65335
97
Look into operator precedence rules.

Henry Wong
author
Marshal
Posts: 22086
88
• 1
And make sure, when you are researching precedence tables, to use tables that also list associativity. As you already mentioned, assignments have right to left assoc, and relational operators have left to right assoc.

Henry