Skip to content

Files

Latest commit

 

History

History
33 lines (22 loc) · 627 Bytes

AssignmentInConditional.md

File metadata and controls

33 lines (22 loc) · 627 Bytes

Pattern: Assignment in conditional

Issue: -

Description

An assignment operator (=) was used in a conditional test. This is usually a typo, and the comparison operator (==) was intended.

Example of violations:

if ((value = true)) {
    // should be ==
}

while (value = true) {
    // should be ==
}

(value = true) ? x : y
(value = true) ?: x

// the following code has no violations
if (value == true) {
}

value == true ? x : y
value == true ?: x

Further Reading