Define a variable to hold the value and then assign it to the desired variable on the next loop.

Does the posted code show the loop you are talking about?

You should use {}s with ALL while and...