- 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.
推薦閱讀
- C程序設計簡明教程(第二版)
- Android和PHP開發最佳實踐(第2版)
- Oracle從新手到高手
- Arduino by Example
- Android 應用案例開發大全(第3版)
- Learning JavaScript Data Structures and Algorithms
- 匯編語言編程基礎:基于LoongArch
- 硬件產品設計與開發:從原型到交付
- 3D Printing Designs:The Sun Puzzle
- 算法訓練營:海量圖解+競賽刷題(入門篇)
- Visual FoxPro數據庫程序設計
- SAP HANA Starter
- 計算機視覺實戰:基于TensorFlow 2
- Python輕松學:爬蟲、游戲與架站
- Building RESTful Web Services with PHP 7