# Creating a loop after a break using Markov Chain in Tikz

I am trying to create something similar to using this example. I modified the source code and this is what I have

\documentclass[tikz]{standalone}
\usetikzlibrary{automata,chains}
\begin{document}
\begin{tikzpicture}[start chain=going left,node distance=2cm]
\node[state, on chain]                 (N+1) {N+1};
\node[state, on chain]                 (N) {N};
\node[on chain]                   (g) {...};
\node[state, on chain]                 (2) {2};
\node[state, on chain]                 (1) {1};
\node[state, on chain]                 (0) {0};
\draw[
>=latex,
%   every node/.style={above,midway},% either
auto=right,                      % or
loop above/.style={out=75,in=105,loop},
every loop,
]
(0)   edge[loop above] node {$p_{0,0}$}   (0)
edge             node {$p_{0,1}$} (1)
(1)   edge[loop above] node {$p_{1,1}$}   (1)
(1)   edge             node {$p_{1,2}$}   (2)
(2)   edge[loop above] node {$p_{2,2}$}   (2)
edge             node {$p_{2,3}$}   (g)
(g)  edge[] node {$p_{N-1,N}$}   (N);
(N)   edge[loop above] node {$p_{N,N}$}   (N)
edge             node {$p_{N,N+1}$}   (N+1)
(N)   edge[bend left] node {$p_{N,N}$}   (0)
(N+1)   edge[loop above] node {$p_{N+1,N+1}$}   (N)
(N+1)   edge[bend left] node {$p_{N+1,N+1}$}   (0)
% The \draw path is like the one above.
\end{tikzpicture}
\end{document}


However, I seem not to get it right. Where did I get this wrong?

You were almost there. You only misplaced the semicolon and confused a label.

\documentclass[tikz]{standalone}
\usetikzlibrary{automata,chains}
\begin{document}
\begin{tikzpicture}[start chain=going left,node distance=2cm]
\node[state, on chain]                 (N+1) {$N+1$};
\node[state, on chain]                 (N) {$N$};
\node[on chain]                   (g) {$\cdots$};
\node[state, on chain]                 (2) {$2$};
\node[state, on chain]                 (1) {$1$};
\node[state, on chain]                 (0) {$0$};
\draw[
>=latex,
%   every node/.style={above,midway},% either
auto=right,                      % or
loop above/.style={out=75,in=105,loop},
every loop,
]
(0)   edge[loop above] node {$p_{0,0}$}   (0)
edge             node {$p_{0,1}$} (1)
(1)   edge[loop above] node {$p_{1,1}$}   (1)
(1)   edge             node {$p_{1,2}$}   (2)
(2)   edge[loop above] node {$p_{2,2}$}   (2)
edge             node {$p_{2,3}$}   (g)
(g)  edge[] node {$p_{N-1,N}$}   (N)
(N)   edge[loop above] node {$p_{N,N}$}   (N)
edge             node {$p_{N,N+1}$}   (N+1)
(N)   edge[bend left] node[below] {$p_{N,N}$}   (0)
(N+1)   edge[loop above] node {$p_{N+1,N+1}$}   (N)
(N+1)   edge[bend left] node[below] {$p_{N+1,N+1}$}   (1);
%         % The \draw path is like the one above.
\end{tikzpicture}
\end{document}