Menu

#1 Short-circuit evaluation & variable initialization

1.0.* (Alpha)
open
Stuart
Assembler (2)
5
2011-04-07
2011-04-07
Stuart
No

The assembler does not throw an error if you put an assignment on the right hand side of an || or && operator.

Example:
$var1 = 9;
if ($var1 == 9 || ($var2 = 5) > 99)
DetailPrint($var2);

The assignment to $var2 may never occur (in this case it will never occur) and yet the assembler will not complain. If $var2 was assigned a value elsewhere prior to this code being executed, then it would still have that value instead of 5.

Stu

Discussion


Log in to post a comment.

MongoDB Logo MongoDB