New Control Syntax

Note The syntax described in this section is currently under revision. Here is the new version which will be implemented in Dotty 0.20.

Scala 3 has a new "quiet" syntax for control expressions that does not rely in enclosing the condition in parentheses, and also allows to drop parentheses or braces around the generators of a for-expression. Examples:

if x < 0 then -x else x

while x >= 0 do x = f(x)

for x <- xs if x > 0
yield x * x

  x <- xs
  y <- ys
  println(x + y)

The rules in detail are:


The Dotty compiler can rewrite source code from old syntax and new syntax and back. When invoked with options -rewrite -new-syntax it will rewrite from old to new syntax, dropping parentheses and braces in conditions and enumerators. When invoked with with options -rewrite -old-syntax it will rewrite in the reverse direction, inserting parentheses and braces as needed.