I need to illustrate a linked list and the addition of one element is there any way I can stop and continue the foreach loop or pause the chain so it doesn't connect elements 5 and 6 for example?
\documentclass{article}
\usepackage{pgffor}
\usepackage{tikz}
\usepackage{xfp}
\usepackage{mathtools}
\usetikzlibrary{calc, shapes.multipart,chains,arrows,positioning}
\tikzstyle{strela} = [thick, ->, >=stealth]
\newcommand\x{9}
\newcommand\y{3}
\newcommand\m{5}
\begin{document}
\begin{tikzpicture}[ar/.style={*->,shorten <=-.28cm},list/.style={rectangle split, rectangle split parts=2, draw, rectangle split horizontal,join=by ar}, start chain=going right]
\foreach \i in {3,...,\the\numexpr\x}{
\node[list,on chain] (\the\numexpr\i) {\i};
}
\node (strela2) [strela, below of= 3, xshift=-0.5cm, yshift=-0.7cm]{HEAD};
\draw (strela2) -> (3);
\node (strela3) [strela, below of= \the\numexpr\x, xshift=-0.5cm, yshift=-0.7cm] {TAIL};
\draw (strela3) -> (\the\numexpr\x);
\node (obj) [right of= \the\numexpr\x,draw,inner sep=6pt] (D) {};
\draw (D.north east) -- (D.south west);
\draw (D.north west) -- (D.south east);
\draw [*->, shorten <=+.10cm] (\the\numexpr\x.center) -- (D);
\node (strela5) [strela, below of= D, yshift=-0.72cm] {NULL};
\draw (strela5) -> (D);
\node[list,below of= \the\numexpr\m, xshift=+1cm] (A) {\the\numexpr\m+0.5};
\end{tikzpicture}
\begin{flushleft}
\vspace{2cm}
\end{flushleft}
\begin{tikzpicture}[ar/.style={*->,shorten <=-.28cm},list/.style={rectangle split, rectangle split parts=2, draw, rectangle split horizontal,join=by ar}, start chain=going right]
\foreach \i in {3,...,\the\numexpr\x/2}{
\node[list,on chain] (\the\numexpr\i) {\i};
}
\node[list,below of= \the\numexpr\m, xshift=+1cm] (A) {\the\numexpr\m+0.5};
\draw[*->] let \p1 = (\the\numexpr\m.two), \p2 = (\the\numexpr\m.center) in (\x1,\y2) -- (A);
\draw[*->] let \p1 = (A.two), \p2 = (A.center) in (\x1,\y2) -- (\the\numexpr\m+1);
\foreach \k in {\the\numexpr\x/2 + 1,...,\the\numexpr\x}{
\node[list, on chain] (\the\numexpr\i) {\k};
}
\node (strela2) [strela, below of= 3, xshift=-0.5cm, yshift=-0.7cm]{HEAD};
\draw (strela2) -> (3);
\end{tikzpicture}
\end{document}



\the\numexprfor simple integers? It shouldn't be necessary. – Qrrbrbirlbel Dec 22 '22 at 21:01