You really should try to understand the mechanism of the loop. In brainfuck, loops are enclosed in [ and ] . This means that the code inside the brackets will be executed and run again if a certain condition is met. For instance:
1: [ 2: cmd1 3: cmd2 4: ] 5: cmd3
Line 1 checks to see if memory[memoryZeiger] 0. If there is one, it goes to line 5. If not, it executes cmd1, cmd2, etc. to line 4. If your interpreter is on line 4, it automatically jumps to line 1 (or it can check the status and move one step further, but let it be simple and suppose that it goes to line1). Then the whole process starts again.
So, to answer your question about the state diagram. You need something like this:
_____________________________ | code[codeZeiger] == '[' | ----------------------------- / \ / \ memory[memoryZeiger] == 0 memory[memoryZeiger] != 0 | | "go to matching ']'" codeZeiger++
Another case for ] should be equivalent.
Btw, matching is important. These brackets can be nested!
source share