Skip to content

Instantly share code, notes, and snippets.

View agustarc's full-sized avatar
🎯
Focusing

Leopold agustarc

🎯
Focusing
View GitHub Profile
fun sum(a: Int, b: Int) = a + b
val a: Int = 10
val b = 2
val c: Int
c = 10
var x: Int = 5
x += 10
fun max(a: Int, b: Int): Int {
if (a > b) {
return a
} else {
return b
}
}
fun max(a: Int, b: Int) = if (a > b) a else b
var max: Int = if (a > b) a else b
switch(x) {
case 1 :
println("x is 1");
break;
case 2 :
println("x is 2");
break;
default :
when(x) {
1 -> print("x is 1")
2 -> print("x is 2")
else -> {
print("x neither 1 nor 2")
}
}
when(x) {
1, 2 -> print("x is 1 or 2")
else -> print("otherwise")
}
when(x) {
in 1..10 -> print("x is in the range")
!in 10..20 -> print("x is outside the range")
else -> print("none of the above")
}