Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

share|improve this question
    
It's possible to use pgffor package outside of TikZ. The loops are not a real part of TikZ also you can use what you want to make loop, while loop etc. –  Alain Matthes Dec 28 '11 at 13:13
add comment

2 Answers

up vote 11 down vote accepted

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}
share|improve this answer
add comment

Update \whiledo is defined in the package ifthen and not calc

TikZ is based on TeX also you can build a while loop with TeX but it's also possible to use different packages like ifthen. With ifthen you can use the macro \whiledo and macros from TikZ.

share|improve this answer
1  
You are right, this a mistake. I would like to say ifthen. Sorry –  Alain Matthes Dec 28 '11 at 15:15
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.