I am trying to stop integrating the equations of motion of a simple pendulum after the bob has crossed the vertical a certain number of times. This is the code I have so far. "k" counts the number of times the bob crosses the vertical.