- Kotlin Programming By Example
- Iyanu Adelekan
- 153字
- 2021-08-27 20:00:11
The while loops
A while loop executes instructions within a block as long as a specified condition is met. The while loops are created using the while keyword. It takes the following form:
while (condition) { … }
As in the case of the for loop, the block is optional in the case where only one sentence is within the scope of the loop. In a while loop, the statements in the block execute repeatedly while the condition specified still holds. Consider the following code:
val names = arrayOf("Jeffrey", "William", "Golding", "Segun", "Bob")
var i = 0
while (!names[i].equals("Segun")) {
println("I am not Segun.")
i++
}
In the preceding program, the block of code within the while loop executes and prints I am not Segun until the name Segun is encountered. Once Segun is encountered, the loop terminates and nothing else is printed out, as shown in the following screenshot:

推薦閱讀
- CMDB分步構建指南
- iOS 9 Game Development Essentials
- 鋒利的SQL(第2版)
- 小程序開發原理與實戰
- Oracle Exadata專家手冊
- Visual FoxPro程序設計習題集及實驗指導(第四版)
- Unity 3D/2D移動開發實戰教程
- Extending Unity with Editor Scripting
- 創意UI Photoshop玩轉移動UI設計
- Python預測分析與機器學習
- Java Web動態網站開發(第2版·微課版)
- 啊哈C語言?。哼壿嫷奶魬穑ㄐ抻啺妫?/a>
- 深入解析Java虛擬機HotSpot
- SQL優化核心思想
- Mastering JavaScript Design Patterns