[Tex/LaTex] Can’t manage to use algorithm packages

algorithms

I'm trying to write some simple pseudocode but I just can't get it to work. It's pseudocode from another paper and I want to change it a little and put it in my paper.

enter image description here

This is the pseudocode I want to write. I tried algorithmicx, algorithm2e and pseudocode but I can't manage to do it with any of them. Are there easier packages for writing pseudocode? I spent the whole morning trying to write an other piece of pseudocode using algorithm2e and it took way too long and the result still looks bad.

And now I get an error that is just ridiculous.

    ! Argument of \algocf@If has an extra }.
    <inserted text> 
                    \par 
    l.98            \If
                 {all variables assigned}

This is my code (it should be the same as the image):

    \begin{algorithm}
    \begin{algorithmic}
        \Loop 
            propagate() - propagate unit clauses
            \If {not conflict} 
                \If {all variables assigned} 
                    \return SATISFIABLE
                \Else
                    decide() - pick a new variable and assign it
                \EndIf
            \Else
                analyse() - analyze comflict and add a conflict clause
                \If{top-level conflict found} 
                    \return UNSATISFIABLE
                \Else
                    backtrack() - undo assignments until conflict clause is unit
                \EndIf
            \EndIf
        \EndLoop
    \end{algorithmic}
    \caption{miniSAT\label{lss}}
    \end{algorithm}

sigh, so frustrating, I hate latex so much why isn't there an alternative.

Anyway, if you can help me, thanks a lot, I'm really desperate at this point.

Best Answer

It's not very clear what you're using; there's probably a package conflict and also wrong syntax. This produces an output that should be what you want:

\documentclass{article}

\usepackage{algorithm,algorithmic}

\begin{document}

\begin{algorithm}
\begin{algorithmic}
  \LOOP 
    \STATE  propagate() - propagate unit clauses
    \IF {not conflict} 
      \IF {all variables assigned} 
        \RETURN SATISFIABLE
      \ELSE
        \STATE decide() - pick a new variable and assign it
      \ENDIF
    \ELSE
      \STATE analyse() - analyze comflict and add a conflict clause
      \IF{top-level conflict found} 
        \RETURN UNSATISFIABLE
      \ELSE
        \STATE backtrack() - undo assignments until conflict clause is unit
      \ENDIF
    \ENDIF
  \ENDLOOP
\end{algorithmic}
\caption{miniSAT\label{lss}}
\end{algorithm}

\end{document}

enter image description here

Related Question