[Scala入門]while文を使った繰り返し処理サンプル
書式
while(condition)
{
statement(s);
}
condition:条件式、trueの場合処理コードを実行します。
使用例
object Demo {
def main(args: Array[String]) {
// ローカル変数
var a = 10;
// while ループ実行
while( a < 20 ){
println( "Value of a: " + a );
a = a + 1;
}
}
}
実行結果
$ 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