I have the following method. Its logic is very simple, if the correct value is given, then call left until it matters (but not empty). When I write it as follows, it works.
fun goNext(from: Node): Node? { var prev : Node = from var next : Node? = from.right if (next != null) { prev = next next = next.left while (next != null) { prev = next next = next.left } } return prev }
If instead I try to shorten the code with a do-while loop, it will no longer use smart next until Node . It shows this error:
Type mismatch. Required: Node<T> Found: Node<T>?
The following code:
fun goNext(from: Node): Node? { var prev : Node = from var next : Node? = from.right if (next != null) { do { prev = next
source share