Vishal Varakhedkar Vishal Varakhedkar - 2 months ago 6x
Brainfuck Question

Print text multiple times in Brainfuck

I tried out this hello world program in Brainfuck. How can I print the text multiple number of times?
Here's my code:

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


Let's think of a 5 character long word like "hello".

So if you want it to print those 5 characters 3 times you could have a code like this:


Let me explain the code:

The first part of the code is the input part:


Then you initialize a variable containing the information that you want to print it 3 times.


Then you have the loop which goes back to the start, prints out those 5 characters, and goes to the variable and decrement it.

[<<<<< //goes back

.>.>.>.>. //print out

>-]  //decrement

If you got the idea, then you can easily improve the code by e.g. putting more loops in it, I just wanted to show you a simple idea.