seems to just run forever
The code is probably in an infinite loop. To find where the loop is, you need to do some debugging. Add some println statements that print out messages as methods are called and as loops are executed. Print out the values of the variables that are used to control the logic so you can see where the program is going wrong. The print out will show you where the looping is happening. When you find that, then you will want to find out why the code is looping. Come back if you need help after you've found where the looping is happening and what the values of the variables are as the loop goes around.