2

I want to have the following output using algorithmic package:

for i = 1 : z do // number of rows
   x = 1 
end for

I use the following tex code:

\begin{algorithmic}
    \FOR{$p=1:r$} // number of rows
        \STATE $x=1$
    \ENDFOR
\end{algorithmic}

It doesn't work. I couldn't find any way to put the comments to the same line with for. Is there any way to do that with the algorithmic package?

EDIT

1.

Code:

\FOR[// loop over all puppies]{$p=1:r$}
    \STATE $x=1$
\ENDFOR

Result:

for i = 1 : z do {// number of rows}
   x = 1 
end for

2.

Code:

\FOR{$p=1:r$ \COMMENT{// number of rows}}
    \STATE $x=1$
\ENDFOR

Result:

for i = 1 : z {// number of rows} do
   x = 1 
end for

Is there any way to get rid of these curly brackets?

3

the package defines

  \newcommand{\algorithmiccomment}[1]{\{#1\}}

so if you go

\renewcommand{\algorithmiccomment}[1]{#1}

the braces will be gone.

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.