[Tex/LaTex] Iterate over an array

loops

Let us assume this example

\documentclass{article}
\newcommand\printlist[1]{
  Loop to get each element \el and its index \ind from {#1}{
    \ind. \el\\
  }
}
\begin{document}
\printlist{A, B, C}
\end{document}

It would give the output

enter image description here

How to implement the loop to get each element and its index from the array {#1}?

Best Answer

What about using a \foreach?

\documentclass{article}
\usepackage{tikz}
\newcommand{\printlist}[1]{%
\foreach \x [count=\xi] in {#1} {\xi. \x\par}%
}
\begin{document}
    \printlist{A, B, C}
\end{document}

enter image description here

Related Question