For repeat loops, instead of re-ordering the stack afterwards to be like before, you can instead see what the stack is going to look like at the end of the loop, and order the stack accordingly before the loop.
Ex. if the stack is [a, b, c] before the repeat, and will be [b, a, c] after one loop, instead of going [b, a, c] -> [a, b, c] N times, you can go from [a, b, c] -> [b, a, c] once, before the loop.
One-time stack re-ordering step for repeat loops
For repeat loops, instead of re-ordering the stack afterwards to be like before, you can instead see what the stack is going to look like at the end of the loop, and order the stack accordingly before the loop.
Ex. if the stack is
[a, b, c]
before therepeat
, and will be[b, a, c]
after one loop, instead of going[b, a, c]
->[a, b, c]
N times, you can go from[a, b, c]
->[b, a, c]
once, before the loop.