[Tex/LaTex] While loops in TikZ

loopstikz-pgf

Is it possible to have while loops in TikZ, or some equivalent loop which only terminates after a certain condition?

Best Answer

You can combine the loop \foreach with the provided command \breakforeach. The following example is copied from the manual.

\begin{tikzpicture}
\foreach \x in {1,...,4}
 \foreach \y in {1,...,4}
   {
    \fill[red!50] (\x,\y) ellipse (3pt and 6pt);
    \ifnum \x<\y
     \breakforeach
    \fi
   }
\end{tikzpicture}
Related Question