Unreachable code should be removed, as it serves no purpose.
Such code is typically a result of incorrect or unintended control flow in code. It is thus important to correctly structure your code and ensure that all code-paths are reachable and can be executed.
The compiler can often detect and warn about unreachable code, helping you identify and fix such issues during development. Removing unreachable code improves code clarity, maintains program correctness, and prevents potential runtime errors.
for (i in 1..2) {
doStuff(i)
break
println() // unreachable
}
Remove unreachable code.
for (i in 1..2) {
doStuff(i)
}