Scala中的判断

1.if ...else

eg:

var score = 96

if (score > 90){

print("优秀")

}else{

print("非优秀")

}

2.if...else if...else 语句

eg:

var score = 96

if (score > 90){

print("优秀")

}else if(score > 80){

print("良好")

} else if(score > 60){

print("及格")

}else{

print("不及格")

}

3.match

相当于 Java中的switch

var score = 61

score match {
  case 69 => {
    print("69")
}
  case 65 =>{
    print("65")
  }
  case _ => print("none")

}

4.for  循环中的if  判断

for (i <- 1 to 10
     if i%2 == 0){
  print(i)

}

猜你喜欢

转载自blog.csdn.net/hzp666/article/details/114702320
今日推荐