In subroutine main: Expected statement(do, let, while, return or if)
Hey guys,
Just started getting my hands dirty with the Jack language and in the midst of writing the Main.main() function, I received an error when I tried to compile:
Compiling /Users/Joseph/workspace/mooc/nand2tetris/projects/09/TicTacToe
In Main.jack (line 7): In subroutine main: Expected statement(do, let, while, return or if)
I can't really pinpoint what's causing the error here, but line 7 corresponds to var char key. My current code is:
class Main {
function void main() {
do Output.moveCursor(11, 21);
do Output.printString("Press Space To Begin");
do Output.println();
var char key;
var boolean start;
let start = false;
while (~start) {
while (key = 0) {
let key = Keyboard.keyPressed();
}
if (key = 64) { let start = true; } // spacebar
}
return;
}
}
I can't see any reason why I'm getting this error. Maybe my eyes are going crazy (as is usually the case when it comes to debugging). What could be the cause here?
Re: In subroutine main: Expected statement(do, let, while, return or if)
Administrator
"var" statements are only allowed at the beginning of subroutines.
function void main() {
var char key;
var boolean start;
do Output.moveCursor(11, 21);
do Output.printString("Press Space To Begin");
do Output.println();
let start = false;