Search code examples
if-statementbrainfuck

Can anyone explain why this brainfuck if/else code doesn't work?


// if x = y then {if_code}; else then {else_code}

,>,< / empty memory

[->-<]> / (x)'y

[>->]< / 0'(y-x)

+[
  {if_code}
  ->>
]< / {if x=y then} (0)'0; {else then} 0'y-x'(1)

[
  {else_code}
  [-]
]< / 0'(y-x)

/ empty memory

/ is to show what the memory should look like, ' is to separate values in the memory, () is used to show where the pointer is, // is for comments, and {} is for descriptions

Whenever I try to run this, no matter what I input, both the if_code and else_code is run.


Solution

  • You have at least three '-' commands hidden in your "comments".