I think the issue was by ths following , Yes. Syntax declarations must come first in the file. The reasoning is (I believe) that it should be simple to extract the grammar needed to parse the rest of the file.
it should still fix some issue You are absolutely right about result being reset to 1 in each iteration of the for loop. It does get reset. "But why doesn't printing result give me 2 every time" you ask.
Syntax error: Non-declaration statement outside function body, but everything there is declaration