How to iteratively define coordinates in TikZ?

You can use (A\i)

\documentclass[]{article}

\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
  \foreach \i in {0,1,2} {
    \coordinate(A\i) at (0, \i);
    \coordinate(B\i) at (1, \i);
  }

  \foreach \i in {0,1,2} {
    \fill[red] (A\i) circle (0.2);
    \fill[blue] (B\i) circle (0.2);
    \draw[orange] (A\i) -- (B\i);
  }
\end{tikzpicture}
\end{document}

enter image description here


You can cut down some code via the count key but it is only worth if you have a lot of them. What you have is basically better in terms of readability in my opinion.

\begin{tikzpicture}
\foreach\x[count=\xi from 0] in {A,B}{
  \foreach\y[count=\yi] in{0,1,2}{
    \coordinate (\x\yi) at (\xi,\y);
  }
}
\end{tikzpicture}