Last active
April 2, 2023 10:11
-
-
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/9afff0825e970497de1f654882df49e56ddd37c8
This file contains 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.1.1" | |
@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