The problem seems to be here. On the first pass, goesForward is assigned the value true. Since moveBackward is not getting executed yet and the value of goesForward does not ever get re-assigned to false, the if statement never gets called on subsequent passes so the loop just goes around ad infinitum. I am, of course, assuming that there are no additional statements in void loop().
Either that or have a counter and change goesForward to true only when the number of counts has been reached. Not quite sure why one would want to do that though? What are you trying to achieve exactly?
Difficult to advise really without having the full picture. What I provided is only an example. I have no way of knowing whether it actually fits your particular scenario or simplifies it...
@BitSeeker
it works somehow, but it was bad advice. The author understands the code very poorly and therefore does not see that he did not solve the problem.
And yes, if you wanted to set the goesForward flag every time before function call - it was enough to do it once, the second call is completely unnecessary here:
Agreed. b707, your approach is neater and my reply was only meant to illustrate that the goesForward flag needed to be cleared somewhere, not propose a final solution. But point taken.