- 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.
推薦閱讀
- Arduino by Example
- Java Web基礎(chǔ)與實例教程(第2版·微課版)
- 跟老齊學(xué)Python:輕松入門
- 基于差分進化的優(yōu)化方法及應(yīng)用
- Mastering Yii
- JavaScript 程序設(shè)計案例教程
- Reactive Android Programming
- TradeStation交易應(yīng)用實踐:量化方法構(gòu)建贏家策略(原書第2版)
- Learning Probabilistic Graphical Models in R
- Mastering Data Mining with Python:Find patterns hidden in your data
- 21天學(xué)通C++(第5版)
- Android應(yīng)用開發(fā)深入學(xué)習(xí)實錄
- Extending Unity with Editor Scripting
- JavaScript悟道
- SSH框架企業(yè)級應(yīng)用實戰(zhàn)