diff --git a/src/main.rs b/src/main.rs index 4476393..04ac4c3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -22,7 +22,7 @@ fn interpret(code: &str) { } '[' => { // loop start - if memory[pc] == 0 { + if memory[head] == 0 { let mut count_brackets = 1; // find nested brackets @@ -47,7 +47,8 @@ fn interpret(code: &str) { } ']' => { // loop terminator - if memory[pc] != 0 { + if memory[head] != 0 { + // jump back to loop beginning if let Some(start_pc) = loop_stack.last() { pc = *start_pc; } else {