if-else statements work very much like the if-else statement you are used to from Java, with a couple of minor differences.
In Java if or else parts that are single statements can drop the curly braces. In Kotlin the curly braces are always required.
In Java if-else is always a statement. In Kotlin if-else can also be an expression that returns a value.
let admission = if (age <= 12) { 7.5 } else { 10.5 }
Kotlin does not offer the traditional for loop. Instead, it uses the for-in loop.
let numbers = [1,2,3,4,5] var sum = 0 for (number in numbers) sum += number println(sum)
If you want something closer to the traditional for loop, you can iterate over a range expression.
let numbers = [1,2,3,4,5] var sum = 0 for (n in 0..(numbers.size-1)) sum += numbers[n] println(sum)
Kotlin also offers a while loop that is very similar to the while loop in Java.