Declare variables in the loop body, add missing gold file (#4269)