Last active
February 3, 2026 20:18
-
-
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/c77f4609ae1b723189d4fe8c1af2d03bb576c315
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 License Version 2.0 (https://www.apache.org/licenses/LICENSE-2.0.txt) | |
| // 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