import util.control.Breaks._
object BreakableTest extends App{
val sample = List(1,2,3,4,5)
for(j <- sample){
breakable{
if(j==2 || j == 4 ) {
break()
}
println(s"打印的值为:$j")
}
}
}
结果为:
打印的值为:1
打印的值为:3
打印的值为:5