As a debugger / test program for my implementation of brainf * ck, I created the following counting loop:
+[[>+]+]
With one byte, wrapping cells and 30k cells with wraparound, this creates an endless loop of counting. It sets each cell to 1, then each cell to 2, etc.
My problem is that when it reaches 255, the inner loop increments the cell to 0, and then the outer loop instantly increments it to 1. This acts like a βdouble stepβ when it overflows instead of a single step. This is the only way I could get the loop to continue indefinitely with this program.
The score for each cell is 0 -> 1 -> 2 ... 254 -> 255 -> 1 ...
Although I would like it to go 0 -> 1 -> 2 ... 254 -> 255 -> 0 -> 1 ...
Just continue the loop when the current cell is zero. I played with variations on the same topic, but none of them could handle it.
This particular program is just a trivial counting program for testing, but what really helps me in future programs is to know how to invert the loop condition, as if I need to do this counting cycle.
source share