In many languages assignments are legal in conditions. I never understood the reason behind this. Why would you write:
if (var1 = var2) { ... }
instead of:
var1 = var2; if (var1) { ... }
It's more useful for loops than if statements.
while( var = GetNext() ) { ...do something with var }
Which would otherwise have to be written
var = GetNext(); while( var ) { ...do something var = GetNext(); }
2.1m questions
2.1m answers
60 comments
57.0k users