Learn Scala 3 Fast: A Note About Comments

Note 2: Comments

We’ll start writing code in the next lesson, but before doing that I also need to note that Scala uses the same comment style that’s used by Java and other C-style programming languages. So you can write comments in either of these three ways:

// a one-line comment

/*
 * a multi-line comment.
 * more comment stuff here.
 */

/**
 * also a multi-line comment
 * with more comment stuff here.
 */

You can also create a one-line comment using this style, but we rarely do because you can just use //:

/* can also do this, but we rarely do */

I’ll use comments with many code examples, so I needed to mention this before we start. For example, one thing I often do is to show the result of a computation after a // comment, such as this:

val a = 1
val b = 2
val c = a + b    // c is 3

Exercises

The exercises for this lesson are available here.

books by alvin