A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://docs.scala-lang.org/scala3/reference/other-new-features/control-syntax.html below:

New Control Syntax

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:

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.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4