import util.control.Breaks._ object work01 { def main(args: Array[String]): Unit = { //方式一 var sum:Int= 0 breakable{ for (i<-1 to 100){ sum =sum+i if ...
import util.control.Breaks._ object work01 { def main(args: Array[String]): Unit = { //方式一 var sum:Int= 0 breakable{ for (i<-1 to 100){ sum =sum+i if (sum >20){ println("當前數是:"+i) break() } } } // 方式二 var loop =true var sum2=0 for (i<-1 to 100 if loop==true){ sum2+=i if (sum2>200){ println("="+i) loop=false } println("i="+i) } } }