Please put your code into [CODE] tags for better readability.
First, your loop needs to end with "done". e.g.:
Code:
while true; do
stuff
morestuff
done
To exit the loop based on some condition, you can use the "break" command.
If you don't have them already, head over to
http://tldp.org and get the Bash Guide for Beginners, and the Advanced BASH Scripig Guide (ABS)