I'm using a language called Jack, as part of the Nand2Tetris course.
This compiles and produces the output I expect when run:
class Main {
function void main() {
var Foo f;
do f.doSomething();
return;
}
}
class Foo {
method void doSomething() {
do Output.printString("Hello, world!");
return;
}
}
But when I add a line...
class Main {
function void main() {
var Foo f;
do f.doSomething();
var int i; // doesn't seem to matter what's here, anything breaks it
return;
}
}
...I get this compiler error:
In Main.jack (line 6): In subroutine main: Expected statement(do, let, while, return, or if)
Why does the additional line make a difference?