[Tex/LaTex] Pseudo code errors in LaTeX

algorithmserrorspseudocode

Can you correct my code plz ?

\documentclass{article}
\usepackage{amsmath}
\usepackage{algorithm}
\usepackage[noend]{algpseudocode}


\begin{document}
\begin{algorithm}
\caption{Algorithme Branch \& Bound}
\label{algorithme_Branch_Bound}
\begin{algorithmic} 
    \STATE $activeset := \left\{\emptyset\right\};$
    \STATE $bestval   :=  NULL;$
    \STATE $currentbest:=NULL;$ \\
    \While{activeset n'est pas vide}{ \     
            \STATE  choisir un n\oe{}ud de branchement, n\oe{}ud $ k \in activeset $ \;
            \STATE  retirer le n\oe{}ud de activeset \;
            \STATE  générer les enfants du n\oe{}ud $k$, enfant $i$, avec $i = 1,...,n_{k}$ \;
            \STATE  et bornes optimistes correspondant $ob_{i}$ \;
                    \FOR{$i=1$ vers $n_{k}$}
                            \IF{$ob_{i}$ pire que bestval} 
                                \STATE tuer l'enfant $i$ \;
                                \ELSIF{l'enfant est une solution complète}
                                        \STATE $bestval := ob_{i}$ \;
                                        \STATE $currentbest := enfant i$ \;
                                        \STATE $rajouter l'enfant i dans activeset$ \;
                    \ENDFOR
}
\end{algorithmic}
\end{algorithm}
\end{document} 

my problem is here :

\FOR{$i=1$ vers $n_{k}$}
                            \IF{$ob_{i}$ pire que bestval} 
                                \STATE tuer l'enfant $i$ \;
                                \ELSIF{l'enfant est une solution complète}
                                        \STATE $bestval := ob_{i}$ \;
                                        \STATE $currentbest := enfant i$ \;
                                        \STATE $rajouter l'enfant i dans activeset$ \;
                    \ENDFOR

Best Answer

You seem to be mixing the syntax of different algorithm-like packages into one:

Also, even though you specify

\usepackage[noend]{algpseudocode}

you still have to provide an accompanying \End... for every programming structure.

Here's your example, with some tweaks, that works:

enter image description here

\documentclass{article}

\usepackage{algorithm,amsmath}
\usepackage[noend]{algpseudocode}

\algnewcommand{\algvar}{\texttt}
\algnewcommand{\assign}{\leftarrow}
\algnewcommand{\NULL}{\textsc{null}}
\begin{document}

\begin{algorithm}
  \caption{Algorithme Branch \& Bound}
  \begin{algorithmic} 
    \State $\algvar{activeset} \assign \{\emptyset\}$;
    \State $\algvar{bestval} \assign \NULL$;
    \State $\algvar{currentbest} \assign \NULL$;
    \While{\algvar{activeset} n'est pas vide}
      \State choisir un n\oe{}ud de branchement, n\oe{}ud $k \in \algvar{activeset}$;
      \State retirer le n\oe{}ud de activeset;
      \State générer les enfants du n\oe{}ud $k$, enfant $i$, avec $i = 1,\dots,n_k$;
      \State et bornes optimistes correspondant $\algvar{ob}_i$;
        \For{$i = 1$ vers $n_k$}
          \If{$\algvar{ob}_i$ pire que bestval}
            \State tuer l'enfant $i$;
          \ElsIf{l'enfant est une solution complète}
            \State $\algvar{bestval} \assign \algvar{ob}_i$;
            \State $\algvar{currentbest} \assign \algvar{enfant}\ i$;
            \State rajouter l'enfant $i$ dans $\algvar{activeset}$;
          \EndIf
        \EndFor
    \EndWhile
  \end{algorithmic}
\end{algorithm}

\end{document}
Related Question