在给定条件为真时重复一个语句或一组语句,它在执行循环体之前判断条件,只要给定条件为真, while 循环语句就会重复执行目标语句。
while - 语法
以下是while循环的语法。
while(condition){ statement(s); }
while - 流程图
![Scala while loop](http://learnfk.xiuxiandou.com/learnfk_scala_while_loop.jpg)
while - 示例
object Demo { def main(args: Array[String]) { //局部变量声明: var a=10; //while循环执行 while( a < 20 ){ println( "Value of a: " + a ); a=a + 1; } } }
将上述程序保存在 Demo.scala 中。以下命令用于编译和执行该程序。
\>scalac Demo.scala \>scala Demo
value of a: 10 value of a: 11 value of a: 12 value of a: 13 value of a: 14 value of a: 15 value of a: 16 value of a: 17 value of a: 18 value of a: 19
参考链接
https://www.learnfk.com/scala/scala-while-loop.html
标签:语句,scala,Demo,Scala,无涯,value,while,循环 From: https://blog.51cto.com/u_14033984/9438051