Switch C-style loops to semicolons before I regret having used commas

This commit is contained in:
K. Lange 2021-01-08 17:14:42 +09:00
parent 0f44617825
commit 8f9c1a4c1d
3 changed files with 5 additions and 5 deletions

View File

@ -441,7 +441,7 @@ Modules are run once and then cached, so if they preform actions like printing o
Kuroku supports C-style for loops, while loops, and Python-style iterator for loops.
```py
for i = 1, i < 5, i = i + 1:
for i = 1; i < 5; i = i + 1:
print(i)
# → 1
# 2

View File

@ -1217,7 +1217,7 @@ static void forStatement() {
emitByte(OP_POP);
} else {
consume(TOKEN_COMMA,"expect ,");
consume(TOKEN_SEMICOLON,"expect ; after var declaration in for loop");
loopStart = currentChunk()->count;
@ -1227,7 +1227,7 @@ static void forStatement() {
exitJump = emitJump(OP_JUMP_IF_FALSE);
emitByte(OP_POP);
if (check(TOKEN_COMMA)) {
if (check(TOKEN_SEMICOLON)) {
advance();
int bodyJump = emitJump(OP_JUMP);
int incrementStart = currentChunk()->count;

View File

@ -28,7 +28,7 @@ print("Hex: " + 0xFF + " Octal: " + 0o123 + " Binary: " + 0b1010)
# This `for init, cond, step:` syntax is possibly temporary? I do intend to
# implement iterators and `for VAR in ITER:` like in Python, but C-style for
# loops are also useful...
for i = 0, i < 10, i = i + 1:
for i = 0; i < 10; i = i + 1:
print("i = " + i)
# Functions work like in Python, though currently no default values.
@ -163,7 +163,7 @@ l.append(1)
l.append(2)
l.append(3)
print("Length after: " + len(l))
for j = 0, j < len(l), j = j + 1:
for j = 0; j < len(l); j = j + 1:
print("j=" + j + ", list[j]=" + l[j])
print("Can we call properties of strings?".__len__()) # Of course we can.