3

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.

  • 1
    Welcome to TeX.SX! Please help us to help you and add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. – Andrew Swann Sep 17 '14 at 12:07
  • Ok, I edited my first post! – supertoto Sep 17 '14 at 12:33
2

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.

| improve this answer | |
  • Thank you! It is exactly what I want. I will have a look at the documentation... – supertoto Sep 17 '14 at 14:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.