- iOS 12 Programming for Beginners
- Craig Clayton
- 203字
- 2021-07-02 15:04:58
The while loop
A while loop executes a Boolean expression at the start of the loop, and the set of statements run until a condition becomes false. It is important to note that while loops can execute zero or more times. Here is the basic syntax of a while loop:
while <condition> { // statement }
Let's write a while loop in Playgrounds and see how it works. You have to add the following:

So, this while loop starts with a variable that begins at zero. Before the while loop executes, it checks to see whether y is less than 50, and, if so, it continues into the loop. Using the += operator, which we covered earlier, we increment y by five each time. Our while loop will continue to do this until y is no longer less than 50. Now, let's add the same while loop after the one we created and see what happens:
while y < 50 {
y += 5
print("y: \(y)")
}
When you are done, you should see the following:

You will notice that the second while loop never runs. This may not seem like it is essential until we look at our next type of loop.
- 社交網絡對齊
- Cisco OSPF命令與配置手冊
- 面向物聯網的CC2530與傳感器應用開發
- WordPress 5 Complete
- 物聯網安全技術
- Getting Started with Grunt:The JavaScript Task Runner
- 智慧光網絡:關鍵技術、應用實踐和未來演進
- 計算機網絡技術及應用
- React Cookbook
- 大型企業微服務架構實踐與運營
- Microservices Development Cookbook
- 互聯網視覺設計(全彩慕課版)
- LiveCode Mobile Development Beginner's Guide
- 天下一家:網絡聯通世界(科學新導向叢書)
- SNS網站構建