Try your experiment with my suggestion for reversing the processing order. (Remember you only edit one line.) Do you see why it runs correctly? The modified program never tries to access an array element which has been moved.
Bill
Comment on Re^3: The error says the value is uninitialized, but it works anyway