When I write

        \textbf{return true}\;

The output is like belowenter image description here

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

if condition then return true;

Is it possible?

3 Answers 3


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

enter image description here

  \KwData{this text}
  \KwResult{how to write algorithm with \LaTeX2e }
  \While{not at end of this document}{
    read current\;
      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}

  • 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, 2014 at 21:34
  • @cagirici: Why is that? Please provide us with a minimal working example (MWE) that replicates your problem.
    – Werner
    Jun 17, 2014 at 21:37
  • it was because my mistake. That worked for me. Thank you very much.
    – padawan
    Jun 17, 2014 at 21:43
  • why line number does not show up? How could I show the line number?
    – alper
    Mar 7, 2017 at 14:44
  • 1
    @Avatar: The package option linesnumbered adds line numbers to each algorithm.
    – Werner
    Mar 7, 2017 at 20:12

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

  • 3
    Why is this answer not higher? Jun 30, 2021 at 22:32

Use \uIf{condition} instead:

        \textbf{return true}\;

From the official alorithm2e documentation (Section: if-then-else macros):

\uIf{condition}{then block without end}

Gives the following output:

if then without end


You must log in to answer this question.

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