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

Similar Programs Chapter Last Updated
Kotlin Continue Kotlin 02-03-2018
Kotlin For Loop Kotlin 30-11-2017
Kotlin Do While Loop Kotlin 19-11-2017
Kotlin While Loop Kotlin 19-11-2017
Kotlin When Statement Kotlin 18-11-2017
Kotlin Nested If Kotlin 18-11-2017
Kotlin If Else If Statement Kotlin 22-09-2018
Kotlin If Statement Kotlin 17-11-2017
Kotlin Print And Println Kotlin 22-09-2018
Kotlin Type Conversion Kotlin 17-11-2017
Kotlin Logical Operators Kotlin 17-11-2017
Kotlin Assignment Operators Kotlin 15-11-2017
Kotlin Arithmetic Operators Kotlin 15-11-2017
Kotlin Data Types Kotlin 12-11-2017
Kotlin Variables Example Kotlin 11-11-2017
Kotlin Comments Example Kotlin 11-11-2017
Kotlin Hello World Kotlin 11-11-2017

1