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

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.

主站蜘蛛池模板: 兴隆县| 明光市| 沂南县| 中西区| 延川县| 威远县| 邓州市| 微博| 固安县| 微博| 松滋市| 陆良县| 湖南省| 清镇市| 海门市| 渝北区| 公主岭市| 乳源| 虞城县| 紫阳县| 苏州市| 宜州市| 溆浦县| 大港区| 红安县| 修文县| 波密县| 伽师县| 大厂| 铜山县| 伊金霍洛旗| 河源市| 正宁县| 永寿县| 临漳县| 彩票| 大港区| 鄄城县| 福清市| 嵊泗县| 安平县|