The syntax is fine. But consider what's actually being done on those lines, compared to your (probable) intent.
It could be something as simple as having closed a loop too soon, or started a loop too late. In any case, none of it is difficult to fix, although it could be cleaned up some.