#判断
scala> def min(x:Int,y:Int):Int={
var a=x
if(x>y) a=y
return a
}
scala> min(1,2)
res1: Int = 1
#循环 ##引申:函数式编程里面尽量使用常量,所以尽量避免 while do? 变量?
while (A) B
do B while A
scala> var m=3
scala> while (m!=0){
println(m)
m-=1
}
3
2
1
#枚举
for (i<-e) E(i)
scala> for ( i <- 1 to 4)
println("No."+i)
No.1
No.2
No.3
No.4
scala> for(i <- 1 to 4; j <- 1 to 2) println(i+j)
2
3
3
4
4
5
5
6
时间: 2024-10-26 01:47:56