Need help getting a program to loop

just change the end of the code to read

Resetting the message received time, without resetting index, will only half solve the problem.