官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 连南| 金乡县| 梁平县| 宁城县| 江孜县| 英吉沙县| 陵川县| 大英县| 太仆寺旗| 宜州市| 松阳县| 天峨县| 阿图什市| 遂川县| 勐海县| 凤凰县| 晋城| 江永县| 昌黎县| 阳东县| 航空| 芦溪县| 双桥区| 海淀区| 广西| 武川县| 石首市| 保亭| 霍林郭勒市| 化州市| 黎川县| 衡阳市| 枣阳市| 全椒县| 崇明县| 武乡县| 临泽县| 津市市| 永春县| 太白县| 丘北县|