Skip to content

Latest commit

 

History

History
23 lines (12 loc) · 1.07 KB

ch3-ExpressionsAndConditionals.asciidoc

File metadata and controls

23 lines (12 loc) · 1.07 KB

Errata

Chapter 3 - Expressions and Conditionals

Loops

Let’s try it out by creating a for-loop that iterates over the sequence we built and printing each message, this time all on the same line instead of on their own lines. Again we only have a single command in the iterated expression, so this time we will leave off the curly braces since they are not necessary here.

scala> for (day <- res0) print(day + ", ")
Day 1:, Day 2:, Day 3:, Day 4:, Day 5:, Day 6:, Day 7:,

The code example should say "res10", not "res0", following the previous example of assigning a value to "res10".

Exercises

6) Can you rewrite the answer to question 6 to fit on one line? It probably won’t be easier to read, but reducing code to its shortest form is an art, and a good exercise to learn the language.

That should be "question 5", not "question 6". Unless you would like a head start on thinking recursively, that is.