How to expect char input to quit loop

Hello, I’m quite newbie with kotlin.

Just tryin to make program that ask to type a word and count them. There is many ways of course to do program, but I’m mostly stuck with char input… How to make program like that expect char x to quit loop?? What’s syntax ? For numbers it’s like
while (line != -1), but == x, =‘x’ !=‘x’ isnt allowed.

fun main(args : Array) {
val numbers = mutableSetOf()
var line = readLine().toString()

while (line is Char("x")) {
    println("Type a word (Type x to exit)")
    line = readLine()!!.toString()!!
    if (line is Char(x))
        numbers.add(line)
}
val total =numbers.count()

println("You typed $total words")

}

Equality in kotlin is checked with ==.
So I imagine you want if (line == "x") { /* your code here */ }

Note that 'x' is a Char while "x" is a String. You can never compare objects of 2 different types, that’s a syntax error.

Great thanks! Problem solved :slight_smile: