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

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.

主站蜘蛛池模板: 科尔| 康定县| 绥阳县| 宜宾县| 泗阳县| 恩平市| 修武县| 墨竹工卡县| 太仓市| 蒙阴县| 玉环县| 洱源县| 肥乡县| 阿拉尔市| 二连浩特市| 措勤县| 桑日县| 广南县| 贵定县| 芦溪县| 二连浩特市| 酒泉市| 彰武县| 理塘县| 大埔区| 清水县| 蛟河市| 通河县| 衡水市| 修武县| 大化| 乌兰浩特市| 自贡市| 醴陵市| 青川县| 新营市| 若尔盖县| 扎赉特旗| 惠来县| 仪征市| 大同县|