This is PHP, but you can easily convert it to anything else. The only use I can find for a while loop in this is to restrict how long the script should go on for, so I set it to stop under 1,000,000 is reached - obviously that could be set to anything.
<?