Convert first loop to iterate with a pointer.