11

I have a similar question as this “For” loop without “do”; “if” statement without “then”:

How can I get rid of the do in a for loop and the then in an if statement when typesetting algorithms using the algorithm and algorithmicx packages?

but I want the same thing for algorithm2e package.

A minimal compilable example:

\documentclass[10pt]{article}
\usepackage[linesnumbered,ruled]{algorithm2e}
\SetKwRepeat{Do}{do}{while}
\SetKw{KwGoTo}{go to}

\begin{document}

\begin{algorithm}
\DontPrintSemicolon
\KwIn{$A,B$}
\KwOut{$C$}
\While{$B > 0$}
{
     $C = C+1$;
     $B = B-1$;
    \uIf{$C > A$}
       {
           \textbf{break}\;
       }
}
\caption{ABC}
\end{algorithm}

\end{document}
3
  • A minimal compilable example should come with the question, so we have something to start with. Look at \SetKwFor and \SetKwIF.
    – Manuel
    Commented Aug 4, 2016 at 11:35
  • Please check it now.
    – Rajat
    Commented Aug 4, 2016 at 11:58
  • Herbert already answered.
    – Manuel
    Commented Aug 4, 2016 at 12:24

1 Answer 1

9
+50
\documentclass[10pt]{article}
\usepackage[linesnumbered,ruled]{algorithm2e}
\SetKwIF{If}{ElseIf}{Else}{if}{}{else if}{else}{end if}%
\SetKwFor{While}{while}{}{end while}%
\SetKwRepeat{Do}{do}{while}
\SetKw{KwGoTo}{go to}
\begin{document}
...

enter image description here

You must log in to answer this question.

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