If it's a single-player game, then you should quit whenever you choose. Although, playing until the end may get you a high score!
If it's a multi-player game, try to not start a game if you can't finish it. Although you are free to quit at any time, it is considered extremely bad form to leave a game that is in progress as your opponent will be left hanging.
If you must leave a multi-player game, tell your opponent(s) that you are leaving the table and click the "Resign Game" or the "Exit Game" button.
However, take our word for it, you'll have the best time using Yahoo! Kids Games if you stick it out until the very end—win or lose!