Add range loops to spec

This commit is contained in:
Sasha Koshka
2024-03-14 22:28:35 -04:00
parent 3dfa029e0d
commit a7df436d77
+7
View File
@@ -276,6 +276,12 @@ statement. The result of the loop may be assigned to any type that satisfies the
assignment rules of all of its break statements. Loops may be nested, and break
statements only apply to the closest containing loop. The value of the loop's
expression is never used.
### For
For is a special kind of loop that evaluates an expression for each element of
an array or slice. It accepts an index declaration and an element declaration,
which are scoped to the loop's body and are set to the index of the current
element and the element itself respectively at the beginning of each iteration.
The assignment rules of a for statement are identical to that of a normal loop.
### Break
Break allows breaking out of loops. It may be assigned to anything, but the
assignment will have no effect as execution of the code after and surrounding it
@@ -362,6 +368,7 @@ this without hand-writing a parser.
["else" <expression>]
<match> -> "match" <expression> <case>*
<loop> -> "loop" <expression>
<for> -> "for" <expression> [<expression>] in <expression> <expression>
<break> -> "[" "break" [<expression>] "]"
<return> -> "[" "return" [<expression>] "]"
<assignment> -> <expression> "=" <expression>