03 · C interpreter
Loop Quest
Type a C loop and watch it run one step at a time. Every trip through the loop becomes a tile, and a tiny pixel hero jumps along them.

Why I built it
Loops are hard to picture
Loop Quest came from seeing people around me, myself included, struggle with C loops. On paper a loop is three short lines, but what happens on each round, and when exactly it stops, is hard to picture. So I made it visible.
At a glance
- Runs
- Entirely in the browser: one HTML file, no server, no libraries.
- Understands
int,for,while,do-while,if/else,break,continue, andprintfwith%d,%iand%c.- Shows
- The current line, a plain-English explanation, every variable, the output, and the loop itself as tiles.
- Sounds
- Chiptune effects generated live with the Web Audio API. No audio files.
- Checked by
- 16 test programs that must print exactly what GCC prints.
How it works
A tiny C interpreter
There's no real C compiler in the browser, so Loop Quest carries its own small C interpreter, written in JavaScript. Your code goes through four stages:
- Your code
- Tokenizer
- Parser
- Step runner
- Screen
Tokenizer
Reads the code character by character and cuts it into tokens: numbers, names, operators like <= and ++, and text in quotes. Comments and #include lines are skipped. Every token remembers its line number, so an error can point at the right line.
Parser
Turns the tokens into a tree, using recursive descent: each level of operator precedence (||, then &&, then ==, then <, then +, then *) is its own small function, so 1 + 2 * 3 groups the way C does. Mistakes come out in plain words, like: Expected ";" but found "}".
Step runner
A JavaScript generator function (function*) walks the tree. After every meaningful action (a declaration, a condition check, an update, a printf) it pauses with yield and hands the screen one event: which line, what kind of step, and a sentence explaining it. The Step button asks for the next event; Play does the same on a timer.
Check i <= 53 <= 5TRUE. Round 3 begins!
Screen
Each loop gets its own lane: the first runs along the ground, the second and third on raised platforms above it. Every check adds a tile showing the loop variable at that moment; the final, failed check adds a red X tile. The hero jumps from tile to tile and printf text floats up from him. It's drawn on a 260×130 canvas and scaled up 3× for crisp pixels.
Behaving like C, not JavaScript
- Every value is forced to a 32-bit integer (
v | 0), so numbers wrap around the way C'sintdoes. - Multiplication uses
Math.imul, so even a hugey * yoverflows like C instead of turning into a big float. - Division cuts toward zero (
-7 / 2is-3), and%keeps the sign of the left side. - Every
{ }block gets its own scope, so an innerint ihides the outer one until the block ends. - After 2,000 steps it stops and explains that the condition probably never becomes false.
Checked, not guessed
Tested against GCC
A visualizer that teaches the wrong answer is worse than none. So the interpreter is tested against GCC, a real C compiler.
- 1The script
scripts/loop-quest-vs-gcc.mjspulls the interpreter straight out ofloop-quest.html, so it tests the exact code visitors run. - 2Each test program is wrapped in
#include <stdio.h>andint main(void) { … }, compiled with GCC and run. - 3The same program runs through Loop Quest. The two outputs must match character for character.
16 programs: the 8 examples in the game, plus 8 cases where JavaScript and C easily disagree:
- Negative division and %
- int overflow
- printf width and %c
- Inner scope hiding an outer variable
- i++ vs ++i
- && short-circuit
- break inside nested loops
- Compound assignment
$ node scripts/loop-quest-vs-gcc.mjs PASS Count to 5 PASS Add 1 to 5 PASS Countdown (while) … 10 more, all PASS PASS && short-circuit PASS Nested break only exits inner loop PASS while with compound ops 16/16 programs print exactly the same as GCC.
One honest footnote: in C, overflowing an int is technically undefined. GCC on normal computers wraps around, and Loop Quest matches that.
Honest about it
What it can't do (yet)
- Use arrays, pointers or strings. Only whole-number variables exist; there's no
[ ], no*p, no text variables. - Call functions.
printfis the only one. Noscanf, and no functions you write yourself. - Handle decimals. No
floatordouble, andprintfknows only%d,%iand%c. - Tell long from int.
longandcharare accepted but stored as a 32-bitint, so alongpast about 2.1 billion wraps where real C wouldn't. - Use switch, ?: or bit operators. They give a friendly error instead of running.
- Draw every loop. Only the first three loops in a program get a lane on screen. A fourth still runs, just without tiles.
- Run very long programs. The 2,000-step safety stop also cuts off long programs that would have finished.