in reply to how to use conditional loops when using while loop
didn't I write something that sounds very similar recently?
you might find some snippets of code in there useful for you.