- 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.
推薦閱讀
- Java應(yīng)用與實(shí)戰(zhàn)
- 程序員考試案例梳理、真題透解與強(qiáng)化訓(xùn)練
- 正則表達(dá)式經(jīng)典實(shí)例(第2版)
- Java程序設(shè)計(jì):原理與范例
- MongoDB權(quán)威指南(第3版)
- 深入淺出React和Redux
- Building Serverless Architectures
- Go語言開發(fā)實(shí)戰(zhàn)(慕課版)
- SQL Server 2008 R2數(shù)據(jù)庫技術(shù)及應(yīng)用(第3版)
- Python編程:從入門到實(shí)踐(第3版)
- Java程序設(shè)計(jì)教程
- Keil Cx51 V7.0單片機(jī)高級語言編程與μVision2應(yīng)用實(shí)踐
- Android應(yīng)用開發(fā)攻略
- Learning Puppet
- 計(jì)算機(jī)視覺實(shí)戰(zhàn):基于TensorFlow 2