kotlin while
var i = 1
while (i < 5) { // while loop
println(i)
i++
}
var i = 1
do { // do-while loop
println(i)
i++
} while (i < 5)
kotlin while
var i = 1
while (i < 5) { // while loop
println(i)
i++
}
var i = 1
do { // do-while loop
println(i)
i++
} while (i < 5)
Kotlin when
val x = 3
when(x) {
3 -> println("yes")
8 -> println("no")
else -> println("maybe")
}
// when can also be used as an expression!
val y = when(x) {
3 -> "yes"
8 -> "no"
else -> "maybe"
}
println(y) // "yes"
kotlin while loop
while ( isTrue() );
while ( isTrue() ) {
println("while!")
}
do {
println("do while!")
} while (isTrue())
how to do a while loop kotlin
//Here is how to do a while loop in kotlin!
//It is very similar to the syntax of javscript if youa have worked with the langauge!
// Program to print line 5 times
fun main() {
var i = 1
while (i <= 5) {
println("Line $i")
++i
}
}
//this will print 5 times!
Line 1
Line 2
Line 3
Line 4
Line 5
//If your try copying and pasting the code put it in this function! Hopefully it will print!
fun main(args: Array<String>) {
println("Hello Bob")
}
kotlin while
var i = 0
while (i < 5) {
println(i)
i++
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us