File tree Expand file tree Collapse file tree 1 file changed +21
-6
lines changed
Expand file tree Collapse file tree 1 file changed +21
-6
lines changed Original file line number Diff line number Diff line change @@ -5,21 +5,36 @@ import (
55 "github.com/NuruProgramming/Nuru/object"
66)
77
8+ const MAX_ITERATIONS = 1_000_000
9+
810func evalWhileExpression (we * ast.WhileExpression , env * object.Environment ) object.Object {
9- condition := Eval (we .Condition , env )
1011 var evaluated object.Object
11- if isError (condition ) {
12- return condition
13- }
14- if isTruthy (condition ) {
12+ iterations := 0
13+
14+ for {
15+ iterations ++
16+ if iterations > MAX_ITERATIONS {
17+ return newError ("mzunguko usio na mwisho umegunduliwa" )
18+ }
19+
20+ condition := Eval (we .Condition , env )
21+ if isError (condition ) {
22+ return condition
23+ }
24+
25+ if ! isTruthy (condition ) {
26+ break
27+ }
28+
1529 evaluated = Eval (we .Consequence , env )
1630 if isError (evaluated ) {
1731 return evaluated
1832 }
33+
1934 if evaluated != nil && evaluated .Type () == object .BREAK_OBJ {
2035 return evaluated
2136 }
22- evaluated = evalWhileExpression (we , env )
2337 }
38+
2439 return evaluated
2540}
You can’t perform that action at this time.
0 commit comments