# Remove “end” in algorithm2e

When I write

\If{condition}
{
\textbf{return true}\;
}


The output is like below

However, I don't want end line. If possible, I want like this:

if condition then return true;

Is it possible?

This is entirely covered in the algorithm2e documentation (section 10.4 if-then-else macros), and is provided by \lIf (short for line If):

\documentclass{article}
\usepackage{algorithm2e}
\newcommand{\True}{\textbf{true}}
\begin{document}
\begin{algorithm}[H]
\SetAlgoLined
\KwData{this text}
\KwResult{how to write algorithm with \LaTeX2e }
initialization\;
\While{not at end of this document}{
\eIf{understand}{
go to next section\;
current section becomes this one\;
}{
go back to the beginning of current section\;
}
\lIf{condition}{\Return{} \True}
}
\caption{How to write algorithms}
\end{algorithm}

\end{document}

• When I use lIf, the semicolon is automatically inserted at the end of true and there is a space between the word and the semicolon, unlike your snapshot. – padawan Jun 17 '14 at 21:34
• @cagirici: Why is that? Please provide us with a minimal working example (MWE) that replicates your problem. – Werner Jun 17 '14 at 21:37
• it was because my mistake. That worked for me. Thank you very much. – padawan Jun 17 '14 at 21:43
• why line number does not show up? How could I show the line number? – alper Mar 7 '17 at 14:44
• @Avatar: The package option linesnumbered adds line numbers to each algorithm. – Werner Mar 7 '17 at 20:12

For that you should add noend option when declaring the package:

\usepackage[noend]{algorithm2e}