CARVIEW |
Select Language
HTTP/2 200
date: Sun, 27 Jul 2025 23:57:34 GMT
content-type: text/html
server: cloudflare
last-modified: Tue, 03 Jun 2025 12:53:02 GMT
nel: {"report_to":"cf-nel","success_fraction":0.0,"max_age":604800}
vary: Accept-Encoding
report-to: {"group":"cf-nel","max_age":604800,"endpoints":[{"url":"https://a.nel.cloudflare.com/report/v4?s=8LapwG4mPgBsgV2u%2F5u9reIK%2FeD4WgP%2FGSYGp6coNxbjbJxV2B4pfuHU9yeketU51MBCnvFFZ6vWpggaiqhdCfqTL3BNYMJj1aEtkaug5lGAbw%3D%3D"}]}
cf-cache-status: DYNAMIC
content-encoding: gzip
cf-ray: 9660146b5cc69dfa-BLR
New Control Syntax

Scala 3 Reference
Edit this page on GitHub
New Control Syntax
Scala 3 has a new "quiet" syntax for control expressions that does not rely on 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
"negative"
else if x == 0 then
"zero"
else
"positive"
if x < 0 then -x else x
while x >= 0 do x = f(x)
for x <- xs if x > 0
yield x * x
for
x <- xs
y <- ys
do
println(x + y)
try body
catch case ex: IOException => handle
The rules in detail are:
- The condition of an
if
-expression can be written without enclosing parentheses if it is followed by athen
. - The condition of a
while
-loop can be written without enclosing parentheses if it is followed by ado
. - The enumerators of a
for
-expression can be written without enclosing parentheses or braces if they are followed by ayield
ordo
. - A
do
in afor
-expression expresses afor
-loop. - A
catch
can be followed by a single case on the same line. If there are multiple cases, these have to appear within braces (just like in Scala 2) or an indented block.
Rewrites
The Scala 3 compiler can rewrite source code from old syntax to 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 options -rewrite -old-syntax
it will rewrite in the reverse direction, inserting parentheses and braces as needed.
In this article