1

I am trying to create a if elseif else algorithm but not its throwing me errors.

The errors say: !Argument of \algosec@Elseselfstrip has an extra }.<inserted text> but cant see that I have inserted an extra } anywhere

Packages:

\usepackage[ruled]{algorithm2e}

Latex code:

 \begin{algorithm}[H]
     \While{true:}
     {
        pl = Poll() \\
        sd = PollSd() \\
        \eIf{time}{
            ok;
        }     
        \ElseIf{response}{
        ok
        }{
        instructions1\;
        instructions2\;
       }

     }
     \caption{Value}
    \end{algorithm}
  • Have you ever heard of a MWE, i.e. a full document with \documentclass{...}, \begin{document}...\end{document}` and the relevant packages? Fragments as this post are not really useful! – user31729 May 7 '16 at 9:04
1

You are using an elsed if hence the name \eIf already. So it expects an else statement

\documentclass[]{article}
\usepackage[ruled]{algorithm2e}
\begin{document}
 \begin{algorithm}[H]
     \While{true:}
     {
        pl = Poll() \\
        sd = PollSd() \\
        \eIf{time}{
            ok;
        }   %<----- Here it expects an else block, basically anything
        \ElseIf{response}{
        ok
        }{
        instructions1\;
        instructions2\;
       }
     }
     \caption{Value}
    \end{algorithm}
\end{document}

You can use different macros for example \uIf etc. to make it a singleton if followed by \ElseIf

  • It only shows if-elsenot if else-if else. – user3580316 May 7 '16 at 9:53
  • @user3580316 That's what I meant with the last sentence. Check the manual it has lots of if else examples. – percusse May 7 '16 at 9:55
  • Can you please show me an example, I am new to latex and having a alot of issues. I would be very grateful. – user3580316 May 7 '16 at 10:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.