Why would you use an assignment in a condition?
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(); } I find it most useful in chains of actions which often involve error detection, etc. if ((rc = first_check(arg1, arg2)) != 0) { report error based on rc } else if ((rc = second_check(arg2, arg3)) != 0) {