# How do I manage flow control with no ELSE statement? (on Turing machine)

I have been given the problem of writing a turing machine with the commands:

if, while, whileNot, read X, write X, goLeft, goRight, HALT


The 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 #
write 0
write 1
goRight


But 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?

• Hm, this is borderline between simulation proof and programming. Community votes, please! – Raphael Apr 14 '15 at 15:21

The following code should work:

whileNot read #