I'm trying to use if in my TikZ picture. For example, I want to draw a point at the origin only if 1 < 2. I can do it, for example, like this:
\begin{tikzpicture}
if 1 < 2 then
\fill (0, 0) circle (1pt);
\end{tikzpicture}
And this code works. But if I try to use if in a loop, then everything stops working. For example, the following code will draw 5 dots instead of 1
\begin{tikzpicture}
\foreach \i in {1, ..., 5}
if \i < 2 then
\fill (\i, 0) circle (1pt);
\end{tikzpicture}
What am I doing wrong and how do I make the code work correct?
The only thing I could find on the Internet is this answer, based on which the desired can be achieved as follows, but the code turns out to be too cumbersome.
\begin{tikzpicture}
\foreach \i in {1, ..., 5} {
\pgfmathparse{ifthenelse(\i<2, 1, 0)}
\ifodd\pgfmathresult\relax
\fill (\i, 0) circle (1pt);
\fi
}
\end{tikzpicture}





