add $ to varname in loop

patch for issue #160
already tested