add for loop

This commit is contained in:
2023-03-20 00:00:17 +00:00
parent a080152aee
commit b56c1fc485
12 changed files with 203 additions and 73 deletions

View File

@@ -108,15 +108,17 @@ func parseForeverLoop(code UNPARSEcode, index int, codeline []UNPARSEcode) (whil
}
func runWhileLoop(loop whileLoop, stack stack, stacklevel int) (any, ArErr) {
newstack := append(stack, newscope())
for {
condition, err := runVal(loop.condition, stack, stacklevel+1)
condition, err := runVal(loop.condition, newstack, stacklevel+1)
newbodystack := append(newstack, newscope())
if err.EXISTS {
return nil, err
}
if !anyToBool(condition) {
break
}
resp, err := runVal(loop.body, stack, stacklevel+1)
resp, err := runVal(loop.body, newbodystack, stacklevel+1)
if err.EXISTS {
return nil, err
}