# \foreach has a problem with ‘initially’ argument in remember part

Is there an error in my code or did I find a bug? It seems like the \foreach statement doesn’t increase \lastn if there is an initally (value) but it works with a manually given initially value (\def\lastn).

This is what I expect …

… and that is what I get …

Here is my MWE:

\documentclass[border=1cm]{standalone}

\usepackage{tikz}

\begin{document}
\begin{tikzpicture}[every node/.style={draw}]
\node (A) at (0,0) {A};
\node (B) at (2,0) {B};
\node (C) at (4,0) {C};
\node (D) at (6,0) {D};
%   DOESN'T WORK
%   \foreach \n [remember=\n as \lastn (initially A)] in {B,C,D} {
%       \draw [->] (\lastn) -- (\n);
%   }
%   WORKS
\def\lastn{A}
\foreach \n [remember=\n as \lastn] in {B,C,D} {
\draw [->] (\lastn) -- (\n);
}
\end{tikzpicture}
\end{document}

-
It works for me with CVS version but not with CTAN version. –  Ignasi Oct 29 '12 at 17:16
Replacing {B,C,D} with {B,...,D} also works correct. –  Qrrbrbirlbel Oct 29 '12 at 17:20
The same issue here tex.stackexchange.com/questions/66844/… In the stable release the pattern somehow should be inline with the initial value otherwise it doesn't seem to like it. –  percusse Oct 29 '12 at 22:50
I confirm that the issue is still there with in the TeXLive 2013 version of TikZ (v 2.10, rcs rev 1.76) –  Olivier Jul 20 '13 at 20:50

It works with \newforeach:

\documentclass[border=1cm]{standalone}
\usepackage{tikz}
\usepackage{loops}
\begin{document}
\begin{tikzpicture}[every node/.style=draw]
\node (A) at (0,0) {A};
\node (B) at (2,0) {B};
\node (C) at (4,0) {C};
\node (D) at (6,0) {D};
\newforeach \n [remember=\n as \lastn initially A] in {B,C,D}
\draw [->] (\lastn) -- (\n);
\end{tikzpicture}
\end{document}


You can try also

\documentclass[border=1cm]{standalone}
\usepackage{tikz}
\usepackage{loops}
\begin{document}
\begin{tikzpicture}
\node at (0,1) [circle,draw,red] {
\foxloop [remember=#1 as \x initially A] {B,C,D,E,F,G,H}{%
$\overrightarrow{\x#1}$\iflastfox.\else,\space\fi
}
};
\end{tikzpicture}
\end{document}

-
OK, thats a workaround, but shouldn’t this bug be fixed in TikI? –  Tobi Oct 30 '12 at 8:17
Where does \newforeach come from? –  Frederick Nord May 2 '14 at 15:18
loops package. –  Ahmed Musa May 4 '14 at 16:02