Skip to content

Instantly share code, notes, and snippets.

@dacr
Last active May 25, 2024 10:20
Show Gist options
  • Save dacr/97f8d18b7dd67557e6911b1012d30e11 to your computer and use it in GitHub Desktop.
Save dacr/97f8d18b7dd67557e6911b1012d30e11 to your computer and use it in GitHub Desktop.
scala3 feature examples - optional control syntax / published by https://github.com/dacr/code-examples-manager #f6b98009-e3e5-4c8a-8c6a-7123d2ebbef6/5aa28c1c1b915b977a75494cc31f5938fea72d5
// summary : scala3 feature examples - optional control syntax
// keywords : scala3, tutorial, @testable
// publish : gist
// authors : David Crosson
// license : Apache NON-AI License Version 2.0 (https://raw.githubusercontent.com/non-ai-licenses/non-ai-licenses/main/NON-AI-APACHE2)
// id : f6b98009-e3e5-4c8a-8c6a-7123d2ebbef6
// created-on : 2021-03-25T11:22:13+01:00
// managed-by : https://github.com/dacr/code-examples-manager
// run-with : scala-cli $file
//> using scala "3.4.2"
@main def go() = {
// -------------------------------------------------------------
if (true) println("true") else println("false")
if true then println("true") else println("false")
// -------------------------------------------------------------
for (i <- 1 to 4) println(i)
for i <- 1 to 4 do println(i)
for
i <- 1 to 4
do
println(i)
for i <- 1 to 4 yield i+1
// -------------------------------------------------------------
try {
1/0
} catch {
case x:Exception => println("boum")
}
try 1/0 catch
case x:Exception => println("boum")
try 1/0 catch case x:Exception => println("boum")
// -------------------------------------------------------------
while(false) {
println("something")
}
while false do println("something")
while false do
println("something")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment