Just a word of advice, you should probably reduce your WHILEs to a minimum... since the higher the number of loops is the more complex your algorithm is. As for the ending problem, whenever you want...