To use program listings in Beamer, you have to add [fragile] after \begin{frame} so that it becomes
\begin{frame}[fragile]
\begin{lstlisting}
program codes here
\end{lstlisting}
\end{frame}
In LyX, if one wants to insert program listings, the same strategy has be to used. To do so, the following steps can be followed.
Step 1. Insert the TeX codes \begin{frame}[fragile]\frametitle{For loop}
Step 2. Type any content for the slides including inserting the program listings
Step 3. Insert the TeX codes \end{frame}
Comments / Discussion / Questions