Dangling else in Kotlin

275 Views Asked by At

I have this doubt guys, I don't know; any example to understand will be great. Does the Kotlin programming language suffer from the "dangling else" problem? If the problem is there then what is the reason in that case?

1

There are 1 best solutions below

0
On BEST ANSWER

Kotlin uses the same methodology as java when it comes to eliminating the dangling else problem. The "else" keyword is simply linked automatically to the nearest "if" or "when" keyword. https://kotlinlang.org/docs/reference/grammar.html#if