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

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.

主站蜘蛛池模板: 达州市| 西华县| 都安| 嘉禾县| 湖北省| 牟定县| 房山区| 尚义县| 合川市| 南宫市| 大田县| 万荣县| 开化县| 大宁县| 靖安县| 浪卡子县| 醴陵市| 浪卡子县| 岳普湖县| 长宁区| 东至县| 云和县| 呼玛县| 靖安县| 林州市| 广东省| 乌兰县| 瑞丽市| 辽宁省| 合肥市| 榆树市| 淮滨县| 盐边县| 麦盖提县| 墨玉县| 库尔勒市| 延长县| 阳高县| 菏泽市| 隆昌县| 虞城县|