Search code examples
loopsbrainfuck

Brainfuck cell print loop


How would one go about creating a loop in Brainfuck to print a cell "x" number of times?

For example:

----[-->+++<]>.

This will print "z" but I want to repeat "z" for 100+ times, how can I do that without using "." in succession to make my code as concise as possible?

Any help would be appreciated!


Solution

  • You can initialize the cell to the value of z without outputting: ----[-->+++<]>, then move one cell right and start a loop of a 100 times: >++++++++++[>++++++++++[**commands here**-]<-].

    Since we moved two cells right to create the nested 10x10 loop, we move two cells left to print, then go back to keep the loop running with <<.>>, and finally we get

    ----[-->+++<]>>++++++++++[>++++++++++[<<.>>-]<-]
    

    Test it here!