- Android Development with Kotlin
- Marcin Moskala Igor Wojda
- 130字
- 2021-07-02 18:48:38
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.
推薦閱讀
- Data Visualization with D3 4.x Cookbook(Second Edition)
- C++面向對象程序設計(第三版)
- JavaScript全程指南
- Oracle從新手到高手
- Python爬蟲開發:從入門到實戰(微課版)
- 算法精粹:經典計算機科學問題的Java實現
- MongoDB,Express,Angular,and Node.js Fundamentals
- Babylon.js Essentials
- Java Fundamentals
- Regression Analysis with Python
- HTML5+CSS3+jQuery Mobile APP與移動網站設計從入門到精通
- 監控的藝術:云原生時代的監控框架
- Getting Started with React VR
- OpenCV 3.0 Computer Vision with Java
- 實戰Python網絡爬蟲