I am using Algorithm2E and I find myself in a situation where I want to express while(!condition);, but I cannot do that on a single line, it seems. This is the closest I got:

\usepackage[linesnumbered, ruled]{algorithm2e}

\While{$\Kwtas(r) = 1$}{ }
$r \gets 0$\\
\caption{Pseudocode of test-and-set usage}


But this puts a single line containing only end. It expresses what I want, but looks quite dirty. How would I be able to express this on a single line?

  • Welcome to TeX.SX. Please provide a "Minimal Working Example" (MWE) that starts with \documentclass, includes all relevant \usepackage commands, ends with \end{document} and compiles without errors, even if it does not produce your desired output.
    – Sandy G
    Commented Dec 4, 2017 at 17:10

1 Answer 1


For every code construction \<code> that puts its content on multiple lines, there is an accompanying \l<code> that puts the content on a single line. You can also define your own \WHILE (and accompanying \lWHILE) using \SetKwFor{<macro>}{<start cond>}{<end cond>}{<end construct>}

enter image description here



\SetKwFor{WHILE}{while (}{)}{}


  \lWhile{$\Kwtas{r} = 1$}{}
  \lWHILE{$\Kwtas{r} = 1$}{}
  $r \gets 0$\;
  \caption{An algorithm}


You must log in to answer this question.

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