From 75048c61c94bd9d92a6a173470cc771476c532b4 Mon Sep 17 00:00:00 2001 From: John Date: Fri, 17 Oct 2025 06:57:37 -0400 Subject: [PATCH] dummy.do: Semicolon elision! --- dummy.do | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/dummy.do b/dummy.do index 2392432..0631e8d 100644 --- a/dummy.do +++ b/dummy.do @@ -4,13 +4,13 @@ // This is a function. It can be called with the call operator. // The function called `main` is the program's entrypoint -fn main() /*-> (&str, bool, i128)*/ { +fn main() -> (&str, bool, i128) { // An if expression is like the ternary conditional operator in C let y = if 10 < 50 { "\u{1f988}" } else { "x" - }; + } // A `while` expression is like the while-else construct in Python, // but it returns a value via the `break` keyword @@ -20,26 +20,28 @@ fn main() /*-> (&str, bool, i128)*/ { } else { // If `while` does not `break`, fall through to the `else` expression false - }; + } + // The same is true of `for` expressions! - // let w = for idx in 0..100 { - // if idx > 2 * 2 { - // break idx - // } - // } else { - // 12345 - // }; + let w = for idx in 0..100 { + if idx > 2 * 2 { + break idx + } + } else 12345; // semicolon operator required here // desugars to - { - let _it = 0..100; - loop if let idx = _it.next() { - if idx > 2 * 2 { break idx } - } else break { 12345 } + let w = match ((0..100).into_iter()) { + __iter => loop match (__iter.next()) { + None => break 12345, + Some (idx) => { + if (idx > (2 * 2)) { + break idx + } + }, + }, }; - // A block evaluates to its last expression, // or Empty if there is none // (🦈, false, 5)