Loop with diamond (TikZ)

How to make the loop from the west corner of diamond to the east corner of diamond is like the figure ?

Figure

Code

       \documentclass[border=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}
\usepackage{amssymb}
\begin{document}

\begin{tikzpicture}[->, >=stealth, auto, semithick,
node distance=3cm,shorten >=2pt,shorten <=2pt,
mynode/.style={fill=white,draw,
diamond,thick,inner sep=5pt}]
\node[mynode] (A) {$1$};
\node[mynode] (B)[right of=A]  {$2$};
\node[mynode] (C)[right of=B]  {$3$};
\node[mynode] (D)[right of=C]  {$4$};

\path[black](A.east) edge[bend left] node{S} (B.west)
(B.west) edge[bend left] node{U} (A.east)
(B.east) edge node{E} (C.west)
(C.east) edge node{S} (D.west)
(B) edge[loop above] node{P} (B)
(B) edge[loop below] node{C} (B)
(C) edge[loop above] node{N} (C);
\end{tikzpicture}
\end{document}


Output

Here is one method, using three separate \draws.

\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}
\usepackage{amssymb}
\begin{document}

\begin{tikzpicture}[->, >=stealth, auto, semithick,
node distance=3cm,shorten >=2pt,shorten <=2pt,
mynode/.style={fill=white,draw,
diamond,thick,inner sep=5pt}]
\node[mynode] (A) {$1$};
\node[mynode] (B)[right of=A]  {$2$};
\node[mynode] (C)[right of=B]  {$3$};
\node[mynode] (D)[right of=C]  {$4$};

\path[black](A.east) edge[bend left] node{S} (B.west)
(B.west) edge[bend left] node{U} (A.east)
(B.east) edge node{E} (C.west)
(C.east) edge node{S} (D.west);
\draw       (B.west) to[out=110,in=70,looseness=3] node{P} (B.east);
\draw       (B.west) to[out=-110,in=-70,looseness=3] node[swap]{C} (B.east);
\draw       (C.west) to[out=110,in=70,looseness=3] node{N} (C.east);
\end{tikzpicture}
\end{document}

• Thank you. Can you clarify the role of looseness=3? Commented Apr 16, 2017 at 11:11
• @Fabrice just try changing the value, and you'll see. Basically it defines how wide the loop will bw. Commented Apr 16, 2017 at 11:48
• Sorry for this request, I had actually tested different values to understand. Commented Apr 16, 2017 at 21:38
• @Fabrice Oh, no worries. For more information about specific keys like that, the TikZ manual is usually helpful, by the way. Search for looseness, and you'll find it fairly quickly. (A useful tip in that regard: commands and keys in code examples and text are usually hyperlinks leading to where they're described, so if your first hit during searching the PDF is code, then you can typically click looseness to jump to its description.) Commented Apr 16, 2017 at 22:09

An alternative with using libraries arrows.meta, bending and quotes and arc instead of loop:

\documentclass[tikz, border=5mm]{standalone}
\usetikzlibrary{arrows.meta, bending, quotes, shapes.geometric}

\begin{document}
\begin{tikzpicture}[-{Stealth[bend]}, auto, semithick,
node distance=3cm,
shorten >=2pt, shorten <=2pt,
mynode/.style={diamond,draw, thick, minimum size=8mm, inner sep=0pt}
]
\node[mynode] (A) {$1$};
\node[mynode] (B)[right of=A]  {$2$};
\node[mynode] (C)[right of=B]  {$3$};
\node[mynode] (D)[right of=C]  {$4$};

\path[black](A.east) edge[bend left, "S"]   (B.west)
(B.west) edge[bend left, "U"]   (A.east)
(B.east) edge["E"]              (C.west)
(C.east) edge["S"]              (D.west);
\draw       ([yshift= 2pt] B.west) arc (235:-55:0.7) node[midway,below] {P};
\draw       ([yshift=-2pt] B.west) arc (-235:55:0.7) node[midway,above] {C};
\draw       (C.west) arc (235:-55:0.7) node[midway,below] {N};
\end{tikzpicture}
\end{document}


In determination of arc radius and end angle the following relations were considered:

arc with P and C are vertical shifted accordingly for 2pt that they not overlap with bend lines between node 1 and 2.

• @ZarkoAnother clever solution Commented Apr 16, 2017 at 21:40
• @ Zarko How to put the value 0.8 rather than the letter S for example ? Commented Apr 19, 2017 at 15:29
• @Fabrice, instead (in selected branch) "S" write "0.8" ... Commented Apr 19, 2017 at 15:36
• @ Zarko With 0.8, it works but with 0,8, it does not work Commented Apr 20, 2017 at 7:38
• problem is comma :) it means, that you have new option in quotes, so it is necessary to isolate it, i.e put 0,8 in curly braces: "{0,8}". Commented Apr 20, 2017 at 8:01