The break and continue keywords

Often when declaring loops, there is a need to either break out of the loop if a condition fulfills, or start the next iteration at any point in time within the loop. This can be done with the break and continue keywords. Let's take an example to explain this further. Open a new Kotlin script file and copy the following code into it:

data class Student(val name: String, val age: Int, val school: String)val prospectiveStudents: ArrayList<Student> = ArrayList()val admittedStudents: ArrayList<Student> = ArrayList()prospectiveStudents.add(Student("Daniel Martinez", 12, "Hogwarts"))prospectiveStudents.add(Student("Jane Systrom", 22, "Harvard"))prospectiveStudents.add(Student("Matthew Johnson", 22, "University of ...

Get Kotlin Programming By Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.