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

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.

主站蜘蛛池模板: 灵寿县| 哈密市| 三明市| 京山县| 黑山县| 天水市| 大悟县| 托克逊县| 阳东县| 克山县| 崇信县| 伊春市| 阿瓦提县| 亳州市| 鄂尔多斯市| 克拉玛依市| 奉化市| 新兴县| 怀柔区| 肇庆市| 武威市| 台中市| 铜川市| 偏关县| 吉林市| 松阳县| 关岭| 长治县| 青阳县| 金秀| 元氏县| 中西区| 江口县| 大新县| 海南省| 嘉定区| 南阳市| 沁源县| 都匀市| 汪清县| 合水县|