diff --git a/examples/loops.ks b/examples/loops.ks new file mode 100644 index 0000000..a1572ed --- /dev/null +++ b/examples/loops.ks @@ -0,0 +1,7 @@ +use std.*; + +for c :: char in chars "hello, world" { + if c == 'l' then ( continue ); + if c == ' ' then ( break ); + dbg c; +} diff --git a/std/lib.ks b/std/lib.ks index ccbfd7b..4bd662a 100644 --- a/std/lib.ks +++ b/std/lib.ks @@ -186,6 +186,10 @@ impl syntax @"syntax".break_with_value = macro (.value) => `( (current loop_context[_]).@"break" $value ); +impl syntax @"syntax".@"continue" = macro _ => `( + (current loop_context[()]).@"continue" () # TODO infer loop context arg +); + const chars :: string -> () with generator_handler[char] = native "chars"; const push_char :: (string, char) -> string = native "push_char"; diff --git a/std/syntax.ks b/std/syntax.ks index 07a5091..dd39090 100644 --- a/std/syntax.ks +++ b/std/syntax.ks @@ -14,7 +14,7 @@ syntax_module { # syntax return <- 2 = "return" value; syntax break_with_value <- 2 = "break" value; syntax break_without_value <- 2 = "break"; - # syntax continue_impl <- 2 = "continue"; + syntax continue <- 2 = "continue"; syntax yield <- 2 = "yield" value; syntax @"loop" <- 3 = "loop" "{" body "}";