Trouble with programming logic

I have tried to use return but it stops the program for a moment then continues. Like i said i'm new to this. I could rewrite it to while loops but, if you could write specific line to exit count() it would be helpfull. I have tried return, break, even goto but nothing seems to work