I have tried to solve this problem following this tutorial, but with no success. I was using \If and \EndIf and now I have switched to \eIf but with no success. I'm using \; at the end of each line to avoid breaking the paragraph. What's wrong in my if?!

  1. http://ctan.mirror.garr.it/mirrors/CTAN/macros/latex/contrib/algorithm2e/doc/algorithm2e.pdf
  2. Misunderstood error with algorithm2e in LateX

     \ForAll {Partition p}
        \ForAll {Edges i=(a,b)}
            \ForAll {bucket in p}
                j=0 % conta i caratteri
                 \ForAll{chr in bucket}
                    \eIf{ chr == a or chr == b}{
                        other2find = set(set((a,b,)) - set((chr,))) \; % give the missing element to find
                         skip1=1 \;
                         \ForAll {other char k} \;
                         \eIf{other2find \== k} {
                            unstableNumber=unstableNumber+1 \;
                             skip2=1 \;
                             break  \; % smette di cercare nei caratteri del bucket
                         \EndIf  \;
                        break  \; 
                %\If{skip1=1} % se ho trovato almeno un nodo in un bucket, salto tutta la partizione
                %            % perche' tanto l'altro nodo sara da qualche parte ma non rendera di certo la partizione
                %            % non stabile
                %   break
                %tutto questo codice non serve perche' e incluso nel break dopo if(other2find)
            break % non serve controllare tutti gli archi per sapere che una partizione non e' stabile
  • Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. Please do not format code as a quotation. It makes it impossible to cut-paste-use.
    – cfr
    Commented Dec 29, 2014 at 3:07
  • In any case, please complete your code either to make it compile (if possible) or to show the error you are having when trying to compile. That is much more useful than a mere fragment of code.
    – cfr
    Commented Dec 29, 2014 at 3:09

1 Answer 1


You seem to be mixing your syntax between what is provided by algorithm2e and that of algorithmicx. The latter uses a \For{..} ... \EndFor and \If{..} ... \EndIf construction while the former uses \For{..}{...} and \If{..}{...} construction together with a \; line-terminating macro.

Here's an algorithm2e implementation:

enter image description here


  \ForAll {Partition p}{%
    $\var{skip1} = 0$\;
    \ForAll {\text{edges} $i = (a,b)$}{%
      $\var{skip2} = 0$\;
      \ForAll {\text{bucket in $p$}}{%
        $j = 0$ % conta i caratteri
        \ForAll{\text{\var{chr} in bucket}}{%
          \eIf{\text{$\var{chr} = a$ or $\var{chr} = b$}}{
            $\var{other2find} = set(set((a,b,)) - set((chr,)))$\; % give the missing element to find
            $\var{skip1} = 1$\;
            \ForAll {\text{other char $k$}}{%
              \If{$\var{other2find} = k$}{%
                $\var{unstableNumber} = \var{unstableNumber} + 1$\;
                $\var{skip2} = 1$\;
                break\; % smette di cercare nei caratteri del bucket
            $j = j + 1$\;
      break\; % non serve controllare tutti gli archi per sapere che una partizione non e' stabile
    \If{not \var{skip2}}{%
      $\var{skip2} = 0$\;


Note that it would be advisable to define a macro for your variable definitions (like skip1, skip2, chr, ...) that you can use throughout your algorithms. You may want to do the same for function calls, or use \call. See the algorithm2e documentation for many more options/details.

You must log in to answer this question.

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