[Tex/LaTex] algorithmic package

algorithmic

I want to write something like

\Repeat {comment}
    \State 
\until

The code:

\documentclass[a4paper]{article}
\usepackage{algorithm} 
\usepackage{algorithmic}
\begin{document}
\begin{algorithm}[H]
\begin{spacing}{1.2}
\begin{algorithmic}
    \STATE Initialize 
    \REPEAT (for each episode)
    \UNTIL $s_t$ is terminal
\end{algorithmic} 
\end{spacing}
\end{algorithm}
\end{document}

But I can not put the comment on the same line of the repeat command.
Could you help me?

Thanks.

Best Answer

In the package documentation of the package algorithm that can be found here, it is written on page 9

Because the mechanisms used to build the various algorithmic structures make it difficult to use the above mechanism for placing comments at the end of the first line of a construct, the commands \IF, \ELSIF, \ELSE, \WHILE, \FOR, \FORALL, \REPEAT and \LOOP all take an optional argument which will be treated as a comment to be placed at the end of the line on which they appear.

As usual you have to use brackets for optional argument. Thus using \REPEAT[for each episode], should give the desired result.