This might sound stupid, but i need help with brainfuck.
so im writing an interpreter in c#, and I tried to use my interpreter on a real piece of code (+[----->+++<]>+.+.
) which should print "hi".
But the while loop never ends, because the first value never gets back to zero, which makes sense, since at the end of each loop the first value should never be 0, since it's only going down, and 1 is not divisible by -5, so why does this code work in other interpreters, whats the logic that would make this actually work in brainfuck.
I'm not asking whats wrong with my interpreter, I'm asking how brainfuck would actually interpret this code, so I can implement it into mine. Because I'm not trying to figure out why this doesn't work in my interpreter, I'm trying to figure out why this code should work in the first place, that way I can optimize my interpreter for more cases.
After some tinkering of the code, and analyzing the values in other interpreters I found that the integers have limits and minimums, which allow it to function. I turned my interpreters code to this to account for them:
if (s == "+")
{
values[pos] += 1;
if (values[pos] > max) { values[pos] = min; }
}
if (s == "-")
{
values[pos] -= 1;
if (values[pos] < min) { values[pos] = max; }
}
Which fixed my main issue.