# an example how to produce ''end if'', ''end for'', and ''end while'' in the algorithm2e environment?

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}


\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}

• Don't load algpseudocode along with algorithm2e and don't mix syntax: the two packages are different and don't go along together. Jul 22 at 14:59

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

\documentclass[11pt]{article}

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

\begin{document}

\begin{algorithm}

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

\end{document}


• 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 Jun 22 at 12:00