# how to generate beamer frames in a foreach loop

I need to generate several frames which each contain an image. I was thinking of looping with \ foreach but it doesn't work

\foreach \nn in{1,2,...,5}{
\begin{frame}[fragile]{}
\includegraphics[width=0.8\textwidth]{cata-\nn.jpg}
\end{frame}
}


This works

\documentclass{beamer}
\usepackage{pgffor}
\begin{document}
\foreach \nn in{a,b,c,duck}{
\begin{frame}
\frametitle{Image \nn}
\centering
\includegraphics[width=0.8\textwidth]{example-image-\nn}
\end{frame}
}
\end{document}


• Does not work with the fragile option... May 20 '20 at 6:16
• @PaulGaborit Yes, that is correct. But one does not need fragile to "generate several frames which each contain an image".
– user194703
May 20 '20 at 6:21