LYR-SEM0202
an assignment written as a condition
The condition of an if, a while or a do … while is an assignment, where a comparison with == is usually meant.
Explanation
An assignment is an expression whose value is the new value of its target, so if (ready = true) compiles — and is true every time. It is almost always == mistyped.
Write == to compare. To assign on purpose and test the value, write the condition in a second pair of parentheses: if ((ready = next())).
Wrong
fn main(): void {
var ready = false;
if (ready = true) {
ready = false;
}
let _ = ready;
}
Right
fn main(): void {
var ready = false;
if (ready == true) {
ready = false;
}
let _ = ready;
}