Making an if(x==y) statement in Brainfuck

The following code is equivalent to your code, except it will stop when the value of the input is 1 (non-printable in ASCII). The < between the loops is required because the last value is 0.

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

It decrements the value after input, checks if it is 0, and loops back if it isn't. If it looped back, it must increment the pointer again to undo the decrement. A sample array might be:

00  02  H  e  l  l  o  _  W  o  r  l  d  00
                                          ^

However, the [<.] prints the reverse of the string (followed by a non-printable 1). The string itself can be printed by moving the pointer to the beginning and moving forward from there, as shown in this code:

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

In this code, the [<] stops when it reaches index 0, the >> moves to index 2 (string start), and the [.>] outputs characters until it reaches the 0 at the end.

If you want to use a different ASCII character, such as space (32), repeat the + and - within the first loop that many times. (Warning: this code will result in values below 0 if there are any characters less than 32 in your input).

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

Start with your significant character – let’s go for $, since it’s ASCII 36:

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

Read input, copying both the input and the significant character over twice, with the second significant character at the end:

[[->+>>>>+<<<<<]>>,[->+>+<<]

for a structure like this:

┌───┲━━━━━━━┱───────┬───────┬───┐
│ $ ┃ blank ┃ input │ input │ $ │
└───┺━━━━━━━┹───────┴───────┴───┘

Subtract the first $ from the first input:

<[->>-<<]>>

If it’s not zero, move forwards three times to the empty cell after the copy of $, then move backwards unconditionally, exiting the loop when the input was $ and otherwise leaving you at a $, ready to start again:

[>>>]<]

After the loop, you’re left on the blank of the matched character. Move forwards to the matching input character and erase it so it isn’t reprinted, move backwards five times to reach the second-to-last input’s intact copy, and keep backing up from there (this doesn’t have to rely on wrapping interpreters and such if you shift forwards a bit at the start):

>>[-]<<<<<[<<<<<]

And then print them out!

>>>>>[.>>>>>]

In all,

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