# Loop with tikz index problem

I need a loop that ends with a test, why this one doesn't work and how use an index in this kind of loop ?

\documentclass[tikz]{standalone}
\usepackage{}
\usetikzlibrary{}

\begin{document}

\begin{tikzpicture}
\count255 = 0
\loop
\draw (0,0) -- (\count225,1) ;
\ifnum\count255 < 4
\repeat
\end{tikzpicture}

\end{document}

-
Regardless of the specific issue, is there a reason for using the low-level \loop instead of PGF's \foreach? Since you're using TikZ already then it would seem more natural to use \foreach. – Loop Space May 9 '14 at 8:49
My problem is that I don't know how much times the loop must operate, I need a test to stop it. I don't post the test because it is MWE, Of course foreach would be an evidence in this case that draws 3 times a vertical line. If there is another solution I'll take it, maybe a break foreach but it's not clean ... ? – Tarass May 9 '14 at 8:55
Sounds reasonable! I don't think \foreach can handle emulate \while loops so that makes sense. – Loop Space May 9 '14 at 8:57
Thanks, I put back my question as it was initialy. – Tarass May 9 '14 at 9:25

You need a \the before the \count255 in the coordinate.

\documentclass{article}
%\url{http://tex.stackexchange.com/q/176229/86}
\usepackage{tikz}
\begin{document}

\begin{tikzpicture}
\count255 = 1
\loop
\draw (0,0) -- (0,\the\count255) ;
\ifnum\count255 < 3
\repeat
\end{tikzpicture}

\end{document}

-
Still have a problem with the stepping of the counter. – Tarass May 9 '14 at 9:09

A possible solution wit LuaLaTeX:

\documentclass{article}
\usepackage{luacode}
\usepackage{tikz}

\begin{document}
\luaexec{
tp = tex.print
count = 1
while count < 3 do
tp("\\begin{tikzpicture}")
tp("\\draw (0,0) -- (0,"..count..");")
tp("\\end{tikzpicture}");
count = count + 1
end
}

\end{document}

-