While Loop in Kotlin
Level 259 keystrokes
Counts down from 3 to 1 with a while loop, then prints "Done!".
Kotlin code
// var is needed because n changes inside the loop1var n = 3// Repeats the block while n is greater than 02while (n > 0) { // Prints the current value: 3, 2, 13 println(n) // Decrease n by 1; the loop ends when n reaches 04 n--5}// Runs once after the loop has finished6println("Done!")Output
3 2 1 Done!
Practice typing this code. Results are not recorded in the rankings.
Symbols in this code
The symbols you type in this Kotlin code and how often they appear.
(× 3)× 3-× 2"× 2!× 1{× 1}× 1=× 1>× 1