Schleife mit Tikz-Indexproblem

Schleife mit Tikz-Indexproblem

Ich brauche eine Schleife, die mit einem Test endet. Warum funktioniert diese nicht und wie verwende ich einen Index in einer solchen Schleife?

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

\begin{document}

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

\end{document}

Antwort1

Sie benötigen ein \thevor dem \count255in der Koordinate.

\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) ;
\advance\count255 by 1
\ifnum\count255 < 3
\repeat
\end{tikzpicture}

\end{document}

Antwort2

Eine mögliche Lösung mit 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}

verwandte Informationen