Fix loops

This commit is contained in:
2025-05-11 13:55:52 +10:00
parent fe3002e661
commit ae858894b9
2 changed files with 22 additions and 17 deletions

View File

@@ -1,8 +1,8 @@
let int myNum 1;
while myNum != 1001 {
while myNum != 1000 {
println myNum;
myNum = myNum + 1;
}
println "The loop has ended";
println "Finished";

View File

@@ -249,20 +249,17 @@ void Interpreter::executeCode(vector<Token> tokens) {
if (skipScope > 0) {
int braceCount = 0;
while (i < tokens.size()) {
int braceCount = 0;
while (i < tokens.size()) {
if (tokens[i].keyword == keywords::OBRAC) {
braceCount ++;
} else if (tokens[i].keyword == keywords::CBRAC) {
if (braceCount == 0) {
skipScope --;
break;
} else {
braceCount --;
}
if (tokens[i].keyword == keywords::OBRAC) {
braceCount ++;
} else if (tokens[i].keyword == keywords::CBRAC) {
if (braceCount == 0) {
skipScope --;
break;
} else {
braceCount --;
}
i++;
}
i++;
}
}
if (repeatScope > 0) {
@@ -414,10 +411,18 @@ void Interpreter::executeCode(vector<Token> tokens) {
loop = tokenIndex - 2 - lengthOfLine;
repeatScope ++;
log.debug("While loop condition is true, will skip back to " + to_string(loop));
} else if (!get<bool>(tokens[i].value.value)) {
int braceLevel = 0;
while (++i < tokens.size()) {
if (tokens[i].keyword == keywords::OBRAC) braceLevel ++;
else if (tokens[i].keyword == keywords::CBRAC) {
if (braceLevel == 0) break;
braceLevel --;
}
break;
}
} else {
log.debug("Condition is false, skipping scope");
skipScope ++;
return;
syntaxError.generalError("Achievement get: How did we get here?");
}
} else {
if (tokens[i].keyword == keywords::VALUE && tokens[i].value.type == valtype::STR && variables.find(get<string>(tokens[i].value.value)) != variables.end()) {