Java – jump to the beginning of the for loop in a Scala program

In the for loop in my Scala code, I want to jump to the beginning of the loop. If the specific condition is true, the following statement will not be executed In Java, I can use 'continue' to do this But 'continue' doesn't seem to work in scala

Please help. Thank you

Solution

If you are using Scala 2.7, from http://www.scala-lang.org/node/257 start

If you are using Scala 2.8

import util.control.Breaks._
// for continue,write this somewhere in your program
val continue = new Breaks
/* use like */
Breaks.breakable {
  for (i <- 1 to 10)
  continue.breakable { if (i % 2 == 0) continue.break; println(i); if (i == 7) Breaks.break }
}


//source http://daily-scala.blogspot.com/2010/04/breaks.html

Note that the usual need to interrupt and continue means that you don't have the functionality Scala wants

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>