0

Could anyone show me by an example how to produce ''end if'', ''end for'', and ''end while'' in the algorithm2e environment? Hello, thank you for your answer, I have tried to upload the algorithm which I want to write In the algorithm2e environment, I have also tried doing some portion of that but could you please help me to make it error-free and completed? Thanks

\documentclass[11pt]{article}
\usepackage[margin=3cm]{geometry}
\usepackage[ruled, noline]{algorithm2e}
\usepackage{algpseudocode}
\begin{document}

Here is my algorithm

\begin{algorithm}
\SetKw{KwBy}{by}
\SetAlgoLined
\DontPrintSemicolon
$k\gets 0$

$M_a\gets 0$

$M_b\gets 0$

\lWhile{something}{

\For{$p \in \{a,b\}$}{

\lIf{something}{

$M_p \gets M_p +1$
 
something

\Else

\If{M_p=M}{

something


\EndIf

\Else{something}
}
}
}
$k\gets k + 1$

\If{$M_a = M$ and $M_b = M$}{
        $M_a \gets 0$
        
        $M_b \gets 0$
        }
        }
        \end{algorithm}
1
  • Don't load algpseudocode along with algorithm2e and don't mix syntax: the two packages are different and don't go along together.
    – egreg
    Jul 22, 2022 at 14:59

1 Answer 1

0

Remove noend from algorithm2e arguments. noend specifically tells the package not to render end-statements.

Here is your MWE:

\documentclass[11pt]{article}

\usepackage[margin=3cm]{geometry}
\usepackage[ruled, noline]{algorithm2e} % <-- HERE
\usepackage{algpseudocode}

\begin{document}

    \begin{algorithm}
        \caption{Your algorithm}
    
        $i\gets 10$\;
        \eIf{$i\geq 5$}
        {
            $i\gets i-1$\;
        }{
            \If{$i\leq 3$}
            {
                $i\gets i+2$\;
            }
        }
    \end{algorithm}
    
\end{document}

enter image description here

1
  • Hello, thank you for your answer, I have tried to upload the algorithm which I want to write In the algorithm2e environment, I have also tried doing some portion of that but could you please help me to make it error-free and completed? Thanks
    – Marso
    Jun 22, 2022 at 12:00

You must log in to answer this question.

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