2

When I run the following code, the pdf is getting generated but I get errors.

 \documentclass[12pt,a4paper,oneside,oldfontcommands]{memoir}
 \usepackage{algorithm2e}
 \usepackage{algorithmicx}

\begin{document}

The following is an example algorithm

    \begin{algorithm}[ht!]
\caption{Algorithm}
 Set count = 1 \linebreak

\While{count $\le$ V}{
     count $\gets$ count + 1 
 }

 \While{dataa $\ne \phi$}{
    \For{V $\epsilon$ data}
        {   \For{a \textless d} 
            {   \If{ccc} 
                    {
                        statements;

                    }
                \ElseIf{cond2}
                    {
                        statements;
                    }
                \EndIf
        }   \EndFor
    }   \EndFor

 }
\end{algorithm}
\end{document}

1 Answer 1

4

Don't mix algorithmicx and algorithm2e. Use one or the other. Here's what you would use with the latter:

enter image description here

\documentclass{article}
\usepackage{algorithm2e,amsmath}

\begin{document}

The following is an example algorithm

\begin{algorithm}[ht!]
  \caption{Algorithm}
  Set $\text{count} = 1$\;
  \While{$\text{count} \leq V$}{
    $\text{count} \gets \text{count} + 1 $
   }
  \While{$\text{data} \neq \phi$}{
    \For{$V \in \text{data}$}{
      \For{$a < d$}{
        \If{ccc}{
          statements\;
        }
        \ElseIf{cond2}{
          statements\;
        }
      }
    }
  }
\end{algorithm}

\end{document}
1
  • Also there are no \endIF and \EndFor. I did not follow the basic syntax. Thanks for the help
    – Harsha
    Commented Jun 20, 2014 at 4:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .