From 71c754190550fbebb0ac8ae92d4bef3cd8b7c94b Mon Sep 17 00:00:00 2001 From: John Long Date: Wed, 5 Jan 2022 23:22:46 -0800 Subject: [PATCH] Switch to readln readln throws an exception when a file hits EOF, wheras readLine returns null. That puts us in an infinite loop if we hit EOF. --- 03_Animal/kotlin/Animal.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/03_Animal/kotlin/Animal.kt b/03_Animal/kotlin/Animal.kt index bac9af08..90fc9f20 100644 --- a/03_Animal/kotlin/Animal.kt +++ b/03_Animal/kotlin/Animal.kt @@ -37,14 +37,14 @@ fun main() { // an answer or a blank string fun ask(question: String): String { print("$question? ") - return readLine()?.uppercase() ?: "" + return readln().uppercase() ?: "" } // Special case for a "yes or no" question, returns true of yes fun askYesOrNo(question: String): Boolean { return generateSequence { print("$question? ") - readLine() + readln() }.firstNotNullOf { yesOrNo(it) } }