[Tex/LaTex] Avoid putting statements on the same line with algorithmicx

algorithmicxindentationline-breaking

I'm writing a simple pseudocode, but I have a problem with a repeat..until block.
Basically what happens is that the return statement that follows the end of this loop gets rendered on the same line as the until clause, which is ugly,
but I can't find a way to put it on a line of its own with the correct indentation.

Here you can have an example:

\documentclass[a4paper,10pt]{article}
\usepackage{algorithm}
\usepackage[noend]{algpseudocode}
\begin{document}
\begin{algorithm}
\caption{test di Fermat}\label{alg:test-fermat}
\begin{algorithmic}[1]
\Procedure{testFermat}{$n, prove$}
    \Repeat
        \State{$a \gets$ numero casuale tra 2 e $n-1$}
        \If{$a^n \not\equiv a \bmod n$}
            \Return composto
        \EndIf
        \State{$prove \gets prove - 1$}
    \Until{$prove > 0$}
    \Return forse primo
\EndProcedure
\end{algorithmic}
\end{algorithm}
\end{document}

I've tried to add a linebreak using \\, but this breaks the indentation.
I've tried using \algorithmicindent to add indentation manually, but this displays "1.5em" instead of a whitespace.
I've tried to add a \State or \Statex after the \Until, but this also breaks the indentation.

Is there a simple way to put the last \Return on a line on its own, without breaking the indentation?

By the way, this happens also with the return inside the If block, but I'm more worried about the one with the until, since it doesn't look so bad with the if.

edit:
I've read this question, but it does not solve the problem.

I don't want to use varwidth because, since I have to fix the until loop, I'd have to manage by hand all indentations[starting a varwidth environment in the middle of the loop breaks other indentations].

Best Answer

This was perhaps a status-by-design choice to allow people to choose between having \Return be on the same line with other statements or be placed on its own. To have it be placed on its own by default add

\algrenewcommand\Return{\State \algorithmicreturn{} }%

to your document preamble.

enter image description here

\documentclass[a4paper,10pt]{article}
\usepackage{algorithm}% http://ctan.org/pkg/algorithms
\usepackage[noend]{algpseudocode}% http://ctan.org/pkg/algorithmicx
\algrenewcommand\Return{\State \algorithmicreturn{} }%
\begin{document}
\begin{algorithm}
  \caption{test di Fermat}\label{alg:test-fermat}
  \begin{algorithmic}[1]
    \Procedure{testFermat}{$n, prove$}
      \Repeat
        \State{$a \gets$ numero casuale tra 2 e $n-1$}
        \If{$a^n \not\equiv a \bmod n$}
          \Return composto
        \EndIf
        \State{$prove \gets prove - 1$}
      \Until{$prove > 0$}
      \Return forse primo
    \EndProcedure
  \end{algorithmic}
\end{algorithm}
\end{document}​