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?
Asked
Active
Viewed 251 times
-1
-
This explains the "dangling else" problem. https://en.wikipedia.org/wiki/Dangling_else. Now do some experiments :-). (The Kotlin reference doesn't explicitly state how dangling else is dealt with ... unlike Java for example.) – Stephen C Dec 03 '17 at 01:22
1 Answers
2
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

Eric Barnes
- 46
- 2