官术网_书友最值得收藏!

Loops

A loop is a control structure that repeats the same set of instructions until a termination condition is met. In Kotlin, loops can iterate through anything that provides an iterator. An iterator is an interface that has two methods: hasNext and next. It knows how to iterate over a collection, range, string, or any entity that can be represented as a sequence of elements.

To iterate through something, we have to supply an iterator() method. As String doesn't have one, in Kotlin it is defined as an extension function. Extensions will be covered in Chapter 7, Extension Functions and Properties.

Kotlin provides three kinds of loops for, while, and do... while. All of them work the same as in other programming languages, so we will discuss them briefly.

主站蜘蛛池模板: 呼图壁县| 仁寿县| 盖州市| 上蔡县| 荥阳市| 和田市| 宝坻区| 民和| 平乡县| 葵青区| 淳化县| 遂溪县| 长宁区| 云南省| 绥芬河市| 饶阳县| 雅江县| 井冈山市| 潼关县| 中超| 会昌县| 米林县| 安吉县| 冕宁县| 壶关县| 龙岩市| 修文县| 平乡县| 建平县| 天等县| 赫章县| 陇南市| 澄城县| 蒙山县| 三原县| 昆明市| 池州市| 遂宁市| 珠海市| 四会市| 满洲里市|