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. Commented Aug 4, 2016 at 11:35
  • Please check it now. Commented Aug 4, 2016 at 11:58
  • Herbert already answered. 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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.