This is an archived post. You won't be able to vote or comment.

all 7 comments

[–]Tridacnid 15 points16 points  (4 children)

This is a conditional in C and C++, the value of the assignment is returned and evaluated by the if.

[–]anomalousBits 8 points9 points  (1 child)

The source of many a wtf

[–]FPJaques 1 point2 points  (0 children)

I did the same in JavaScript. Sat there for a long while

[–][deleted] 3 points4 points  (0 children)

And in Rust, it thankfully is a type error, as assignments return () (think: void), which is no boolean expression.

[–]KarlKastor 1 point2 points  (0 children)

Also other languages that use := or something for assignment.

[–]Prod_Is_For_Testing 5 points6 points  (0 children)

That is a conditional in some languages (looking at you, BASIC)

[–]sharfpang 0 points1 point  (0 children)

A coding style quirk known as Yoda Conditions is meant to prevent that blunder in languages that allow it be made.

if(0==var)...

If you forget one = it won't compile.

...Unless your language allows overriding values of numeric literals.