%=======================================================
%=====           The "HESITATION" Routine          =====
%=======================================================
%===== The Algorithm Feeds Back The Previous Input =====
%===== Each Time A New Input Comes. It Needs Two   =====
%===== Edges From Each Mode, One For Each Possible =====
%===== Output Character.                           =====
%=======================================================

function FiniteStateMachineI()

clear
clc

Input =  input('Input Value To Finite State Machine (0 or 1, 9 for Exit): ');
Output = 0;
State = 0;

while (Input ~= 9)
    Input =  input('Input Value To Finite State Machine (0 or 1, 9 for Exit): ');
    if (State == 0)
        if (Input == 0)
            State = 0;
                Output = 0;
        end
        if (Input == 1)
            State = 1;
                Output = 0;
        end
    elseif (State == 1)
        if (Input == 1)
            State = 1;
                Output = 1;
        end
        if (Input == 0)
            State = 0;
                Output = 1;
        end
    end
    display(Output);
end
end