-
Notifications
You must be signed in to change notification settings - Fork 0
Kotlin If, When and While
Maria Maged M edited this page Apr 12, 2020
·
4 revisions
- if is nearly ubiquitous in computer programming.
if(i > 10) {
// Do something.
}
else {
// Do something else.
}if(i > 10) {
// Do something.
}
else {
// Do something else.
}
// Yes, it is the same as Java syntax.if(i > 10)
# Do something.
else
# Do something.
end val i = 3
if(i > 10) {
println("Something")
}
else {
println("Something else")
}-
For single-line conditional work, you can skip the braces.
val i = 3
if(i > 10) println("Something") else println("Something else")- It also supports
else ifin addition to a simple else:
val i = 3
if(i > 10) println("Something")
else if(i > 2) println("Something else")
else println("And now for something completely different")