I have been given the problem of writing a turing machine with the commands: if, while, whileNot, read X, write X, goLeft, goRight, HALTThe problem was simply calculate a two's complement number, from number with \$ on the left and # on the right, ex: $10110100#I started by writing this pseudocode to flip the bits:whileNot read #    if read 1        write 0    if read 0        write 1    goRightBut then I realized once 'write 0' executes, 'if read 0' will immediately be true and undo my work. I need a statement that is effectively 'else if read 0', is there any turing trickery that I can employ to do something like this?
How do I manage flow control with no ELSE statement? (on Turing machine)
turing machines;simulation
The following code should work:whileNot read #    while read 1        write 0        goRight    while read 0        write 1        goRightAs for implementing IF-THEN-ELSE in general, it depends on the exact semantics of your programming language, which you haven't specified.