scala Quick Start series break and continue []

        Benpian as the scala Quick Start eighth series of articles blog for everyone to bring about the break and continue relevant content.

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

  • ImportingBreakspackageimport 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
Here Insert Picture Description


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
Here Insert Picture Description


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!
Here Insert Picture Description

Published 149 original articles · won praise 1348 · Views 350,000 +

Guess you like

Origin blog.csdn.net/weixin_44318830/article/details/103963654