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 811811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T01:06:10+00:00 2026-05-15T01:06:10+00:00

In Chapter 3 of Programming Scala , the author gives two examples of for

  • 0

In Chapter 3 of Programming Scala, the author gives two examples of for loops / for comprehensions, but switches between using ()’s and {}’s. Why is this the case, as these inherently look like they’re doing the same thing? Is there a reason breed <- dogBreeds is on the 2nd line in example #2?

// #1 ()'s
for (breed <- dogBreeds
  if breed.contains("Terrier");
  if !breed.startsWith("Yorkshire")
) println(breed)

// #2 {}'s
for {
  breed <- dogBreeds
  upcasedBreed = breed.toUpperCase()
} println(upcasedBreed)
  • 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-15T01:06:11+00:00Added an answer on May 15, 2026 at 1:06 am

    If you read the green Tip:

    for expressions may be defined with
    parenthesis or curly braces, but using
    curly braces means you don’t have to
    separate your filters with semicolons.
    Most of the time, you’ll prefer using
    curly braces when you have more than
    one filter, assignment, etc.

    So for comprehension with () and {} are the same the only thing that change is the separator used : for () you have to use a semicolon ";" as separator and for {} you use new line.

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

Sidebar

Related Questions

In Chapter 9 of Programming In Scala, there is an example method like this:
In the book Programming In Scala, chapter 23, the author give an example like:
I am reading Programming In Haskell, in the 8th chapter, the author gives an
I'm reading Programming Scala . At the beginning of chapter 4, the author comments
This is a programming exercise from Chapter 6 of The Art and Science of
Working through a sample in Chapter 3 of Programming in Scala, the following code
This problem comes out of the dynamic programming chapter in The Algorithm Deisgn Manual
Ive been using Open GL ES 2.0 Programming guide and am following chapter 9
This is a sample from book Cocoa Programming For Mac Os X 3rd(HD) chapter
L.S. I'm just learning Scala using Programming in Scala by Odersky et al. In

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.