Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot figure out if statement

Tags:

brainfuck

Here is the code i am working with, it tests for the input of 'b' and should output 'Y' if there was anything else inputted.

Please, nobody ask why I chose to use 'Y' for a false value..

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


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

Would like the equivalent of

char c;
c = getchar();
if (c == 'b')
    putchar('Y');

I am getting no output (directed it at a file and hexdumped it, as well as nothing on the screen) no matter what I put into the program

like image 497
phyrrus9 Avatar asked Dec 07 '22 05:12

phyrrus9


1 Answers

After almost 2 years you probably don't need this anymore, but here's my version of "if - else" statement:

+++++ +++++
+++++ +++++
+++++ +++++
+++           (this is the value you want to check, in this case it's the "!")

> , <         (then you take input an char to compare)
[ - > - < ]   (after that you have to check if their ascii values are the same)
>>            (and initialize the answer on "true")

+++++ +++++
+++++ +++++
+++++ +++++
+++++

< [ - > ] > . (if "false", this loop will be executed and the answer won't be printed)

Hope it's usefull to someone today. :D

like image 192
Ustym Ukhman Avatar answered Dec 15 '22 04:12

Ustym Ukhman