Kotlin Break Statement
Chapter:
Kotlin
Last Updated:
27-01-2018 08:00:13 UTC
Program:
/* ............... START ............... */
fun main(args: Array<String>) {
for (i in 1..10) {
if (i == 5) {
break
}
println(i)
}
var sum = 0
var number: Int
while (true) {
print("Enter a number: ")
number = readLine()!!.toInt()
if (number == 0)
break
sum += number
}
print("sum = $sum")
}
/* ............... END ............... */
Output
1
2
3
4
Enter a number: 34
Enter a number: 13
Enter a number: 12
Enter a number: 2
Enter a number: 3
Enter a number: 3
Enter a number: 0
sum = 67
Notes:
-
As like java break statement is used to break the iteration from the looping statements.
Tags
Break Statement , Kotlin, Break Expression