issue6291: declare "command" variable within loops