流程控制
作者:互联网
import scala.language.postfixOps
import scala.math.BigDecimal.double2bigDecimal
object xun {
def main(args: Array[String]): Unit = {
//1.循环守卫
for (i <- 1 to 10){
if(i != 5){
println(i)
}
}
for (i <- 1 to 10 if i != 5){
println(i)
}
println("==========")
//2.循环步长
for (i <- 1 to 10 by 2){
println(i)
}
println("----------")
for (i <- 13 to 30 by 4){
println(i)
}
println("----------")
for (i <- 30 to 13 by -3){
println(i)
}
println("----------")
for (i <- 1 to 10 reverse){
println(i)
}
println("----------")
for (i <- 1.0 to 10.0 by 0.33 ){
println(i)
}
println("----------")
//3.循环嵌套
for (i <- 1 to 3 ;j <- 2 to 5){
println(" i = " + i + " j = " + j)
}
println("----------")
//打印九九乘法表
for (i <- 1 to 9 ){
for (j <- 1 to i ){
print(s"$j * $i = ${i * j} \t")
}
println()
}
}
}
标签:控制,九九乘法,scala,流程,----------,步长,循环,println 来源: https://www.cnblogs.com/zml603/p/16274378.html