[Tex/LaTex] naming paths inside a TikZ foreach loop

loopstikz-pgf

Is it possible to create named paths inside a foreach loop with the name depending on the counter?

I want to write something like

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{intersections}

\begin{document}

\begin{tikzpicture}
    \foreach \i in {1,2,...,6}
        \draw[name path=line\i] (-3,-\i) -- (3,\i);
    \draw[name intersections={of=line1 and line2}] (intersection-1) circle (5pt);
\end{tikzpicture}

\end{document}

but this throws the following error:

! Missing \endcsname inserted.
<to be read again> 
                   \OT1\i 
l.11    \draw (0,3) circle (3);

Is this a bug or am I doing something wrong? What should I do instead?

Best Answer

It also possible a bit less hacky. (pgf-manual p. 496) Look at this modified code:

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{intersections}

\begin{document}

\begin{tikzpicture}
    \foreach \i in {1,2,...,6}
    {
  \draw[name path global/.expanded=line\i] (-3,\i) -- (3,-\i);
    }
\draw[name intersections={of=line1 and line2}] (intersection-1) circle (5pt);
\end{tikzpicture}

\end{document}