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

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.

主站蜘蛛池模板: 澄江县| 新兴县| 华阴市| 句容市| 太仆寺旗| 酉阳| 京山县| 霍邱县| 克拉玛依市| 韩城市| 运城市| 祥云县| 娱乐| 夏邑县| 临泉县| 巫溪县| 阿坝| 河北省| 建阳市| 普安县| 石楼县| 全椒县| 涪陵区| 石台县| 志丹县| 康平县| 石门县| 台北市| 兰考县| 岳阳市| 长寿区| 皋兰县| 扎赉特旗| 石首市| 张掖市| 聊城市| 南岸区| 蒲江县| 平南县| 巴塘县| 沁阳市|