Loop statement fix