Programmatically constructing a closed path with tikz is easy:
\path (a0) \foreach \i in {1, ..., 7} {-- (a\i)} -- cycle;
But it forces to single out the first point. Reversing the construction pattern is rejected by tikz:
\path \foreach \i in {0, ..., 7} {(a\i) --} cycle;
and I suppose there are good reasons for that (I read an explanation about that on SE, but have lost reference to that answer edit found it here).
Unfortunately, if the building pattern is more complex than just adding point after point, the working solution can be quite tedious :
\path \foreach \i in {0, ..., 8} {(a\i) -- (\i*10:3) -- (b\i) --} cycle;
would be quite compact a way, but to get it to work I would need to code:
\path (a0) -- (0:3) -- (b0) \foreach \i in {0, ..., 8} {-- (a\i) -- (\i*10:3) -- (b\i)} -- cycle;
And that isn't even a complicated computation.
Is there some magic that would allow me to build the entire path using only \foreach ?
EDIT: example of such a construction
\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\fill[gray, rounded corners=25pt, even odd rule] (30:5) -- (120:3) -- (0:4) \foreach \i in {1, ...,19} {-- (30+18*\i:5) -- (120+18*\i:3) -- (18*\i:4)} -- cycle;
\end{tikzpicture}
\end{document}
