Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5971745
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:33:34+00:00 2026-05-22T20:33:34+00:00

In a for loop in my Scala code, i want to skip to the

  • 0

In a for loop in my Scala code, i want to skip to the beginning of the loop and not execute following statements if a particular condition is true. In Java i can use ‘continue’ for doing this. But ‘continue’ does not seem to work in Scala.
So how can i skip to the beginning of my loop in a Scala program ?

Please Help
Thank You.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T20:33:36+00:00Added an answer on May 22, 2026 at 8:33 pm

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

    These keywords are not included in Scala 2.7, and must be implemented in a different way. For break, the simplest thing to do is to divide your code into smaller methods and use the return to exit early. For continue, a simple approach is to place the skipped-over parts of a loop into an if.
    Scala 2.8 will include break, but not continue.

    If you’re 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 normally needing break and continue means that you aren’t being as functional as Scala would like you to be.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following code works fine in Scala 2.8 but not in 2.9.0.1 (copy and
I have the following Scala code. import scala.actors.Actor object Alice extends Actor { this.start
I have a simple piece of Scala code. I loop sequentially through a List
This code gives compilation error: import scala.util.continuations._ object CTest { def loop: Nothing =
Given the following code: class A extends Actor { def act() { loop {
I usually loop through lines in a file using the following code: open my
In Scala, you often use an iterator to do a for loop in an
/// \todo Loop must be rewritten ... /// \todo Delete this loop Can Doxygen
I want to loop over the contents of a text file and do a
I want to loop over the elements of an HTML form, and store the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.