Add continue statement.

This commit is contained in:
Stephen Chung
2020-04-01 16:22:18 +08:00
parent 9aff10aca4
commit 4ea2fb88ae
6 changed files with 69 additions and 37 deletions

View File

@@ -12,8 +12,9 @@ fn test_loop() -> Result<(), EvalAltResult> {
loop {
if i < 10 {
i += 1;
if x > 20 { continue; }
x = x + i;
i = i + 1;
} else {
break;
}
@@ -22,7 +23,7 @@ fn test_loop() -> Result<(), EvalAltResult> {
return x;
"
)?,
45
21
);
Ok(())

View File

@@ -6,8 +6,18 @@ fn test_while() -> Result<(), EvalAltResult> {
assert_eq!(
engine.eval::<INT>(
"let x = 0; while x < 10 { x = x + 1; if x > 5 { \
break } } x",
r"
let x = 0;
while x < 10 {
x = x + 1;
if x > 5 { break; }
if x > 3 { continue; }
x = x + 3;
}
x
",
)?,
6
);