Issue #7969 by tj: Fixed loop