Benpian as the scala Quick Start eighth series of articles blog for everyone to bring about the break and continue relevant content.
Article Directory
break和continue
- In the scala, like Java and C ++ break / continue keyword is removed
- If you must use break / continue, we need to use the class scala.util.control Break package breable and break method.
Achieve break
usage
- ImportingBreakspackage
import scala.util.control.Breaks._
- The expression for use breakable wrap
- for expressions where needed to exit the loop, add the break () method call
Examples
The use of digital printing for expressions 1-100, if the number reached 50, the exit for expression.
Reference Code
Continue to achieve
usage
continue implementation of the break is similar, but a little different:
[!NOTE]
achievebreak breakable {} is the expression for the entire wrap, To achievecontinue breakable {} is the expression for the loop comprising upOn it
Examples
Print digital 1-100, for use expressions to traverse, if the number divisible by 10, do not print.
Reference Code
This blog to end here, small partners who are interested can continue to focus on the next one will bring you yo ~ 方法
related content, so stay tuned!