Perhaps you want to only change the start/end points of the loop when the loop reaches a boundary? The [latch] operator may help. Feed your in2 and in3 inputs into the left inlets of latches, and some control signal into the right inlets. The control signal should be 1 when the loop boundary is reached, and 0 otherwise. E.g. The [== -1] fed through a [not] might be a good control signal.