Last active
May 25, 2024 10:20
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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