- Learning Scala Programming
- Vikash Sharma
- 139字
- 2021-06-30 19:07:54
The do while loop
The do while loop does not differ a lot from the while loop. Generic syntax for do while loop is:
do
... // Block of Code to be executed
while(condition check (if it's true))
The do while loop ensures that the code in block gets executed at least once and then checks for the condition defined in a while expression:
scala> do println("I'll stop by myself after 1 time!") while(false)
The following is the result:
I'll stop by myself after 1 time!
It's a simple example where our statement is getting printed just once before the condition passed to the while loop is false. This is how we can use -do while loops in Scala.
You may want to try out the PagePrinter example using the while and do while loops.
推薦閱讀
- Azure IoT Development Cookbook
- Java加密與解密的藝術(第2版)
- Python Tools for Visual Studio
- MySQL數(shù)據(jù)庫管理與開發(fā)實踐教程 (清華電腦學堂)
- Python機器學習經典實例
- Yocto for Raspberry Pi
- 區(qū)塊鏈底層設計Java實戰(zhàn)
- Flowable流程引擎實戰(zhàn)
- QGIS Python Programming Cookbook(Second Edition)
- Unity 5.X從入門到精通
- ASP.NET求職寶典
- Instant Apache Camel Messaging System
- Python編程入門(第3版)
- Isomorphic Go
- Managing Windows Servers with Chef