Fixed for loop code generation