if
statements that can be collapsed into one KT-W1048Collapsing nested if statements into one improves code readability by making it more concise and easier to understand. It simplifies the logic, reduces cyclomatic complexity, and can lead to better performance. Debugging becomes easier, and code maintainability is enhanced. It is important to strike a balance between readability and line length while considering the overall code structure.
val i = 1
if (i > 0) {
if (i < 5) {
println(i)
}
}
Merge the if
statements to improve code readability.
val i = 1
if (i > 0 && i < 5) {
println(i)
}