The loop now works successfully