Break and continue keywords are working

This commit is contained in:
2022-08-20 20:08:22 +01:00
parent daceaa5492
commit 18c5fb6add
7 changed files with 194 additions and 35 deletions

View File

@@ -1,20 +1,18 @@
//test true jump
if (true) {
assert true, "if-then failed";
assert true, "if-then failed (1)";
}
else {
assert false, "if-then failed";
assert false, "if-then failed (2)";
}
//test false jump
if (false) {
assert false, "if-then failed";
assert false, "if-then failed (3)";
}
else {
assert true, "if-then failed";
assert true, "if-then failed (4)";
}
@@ -36,4 +34,49 @@ for (var i = 0; i < 20; i = i + 1) {
assert forCache == 19, "for-loop failed";
print "All good";
//test break - while
var breakWhileCache = 0;
while(true) {
breakWhileCache = breakWhileCache + 1;
if (breakWhileCache >= 7) {
break;
}
}
assert breakWhileCache == 7, "break-while failed";
//test continue - while
var continueWhileCache = 0;
while (continueWhileCache < 10) {
continueWhileCache = continueWhileCache + 1;
if (continueWhileCache >= 7) {
continue;
}
assert continueWhileCache < 7, "continue-while failed";
}
//test break - for
for (var i = 0; i < 10; i = i + 1) {
if (i >= 7) {
break;
}
assert i < 7, "break-for failed";
}
//test break - continue
for (var i = 0; i < 10; i = i + 1) {
if (i >= 7) {
continue;
}
assert i < 7, "continue-for failed";
}
print "All good";