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

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.

主站蜘蛛池模板: 阳曲县| 洪湖市| 阿拉善左旗| 晋中市| 五大连池市| 海伦市| 龙州县| 馆陶县| 珠海市| 裕民县| 陵川县| 承德县| 和硕县| 西藏| 武平县| 莱州市| 长沙市| 无棣县| 佳木斯市| 泰顺县| 泗阳县| 江山市| 彰武县| 中阳县| 托克托县| 南丰县| 依安县| 天祝| 黑水县| 广昌县| 湟源县| 左贡县| 梁山县| 大化| 威远县| 郯城县| 吴忠市| 大庆市| 额尔古纳市| 贵定县| 兰溪市|