How to align comments in algorithmic environment to the right? For \Comment, if the comment is too long it gets wrapped and starts at the beginning of next line. It would look better if it was aligned to the right side.

\documentclass{report}
\usepackage{algorithm}
\usepackage{algpseudocode}

\begin{document}
\begin{algorithm}
\begin{algorithmic}
\Function{foo}{x}
\State $x \gets 1$ \Comment{very long comment}
\EndFunction
\end{algorithmic}
\end{algorithm}
\end{document}

-

Wrap the comment inside a top-aligned \parbox of specific width. Consider the following example:

\documentclass{report}
\usepackage{algorithm}% http://ctan.org/pkg/algorithms
\usepackage{algpseudocode}% http://ctan.org/pkg/algorithmicx
\begin{document}
\begin{algorithm}
\begin{algorithmic}
\Function{foo}{x}
\State $x \gets 1$ \Comment{very long comment
very long comment very long comment very long comment very long comment
very long comment very long comment very long comment very long comment
very long comment very long comment very long comment very long comment
very long comment very long comment very long comment very long comment.}
\State $x \gets 1$ \Comment{\parbox[t]{.5\linewidth}{very long comment
very long comment very long comment very long comment very long comment
very long comment very long comment very long comment very long comment
very long comment very long comment very long comment very long comment
very long comment very long comment very long comment very long comment.}}
\EndFunction
\end{algorithmic}
\end{algorithm}
\end{document}

-