[Tex/LaTex] ! LaTeX Error: Something’s wrong–perhaps a missing \item

algorithmic

I am using TEXMAKER. Here is a code segment.

\usepackage{algorithmic} 
begin{algorithmic}
\FOR {$i\gets0$ to $n$} \do
    \FOR {$j \gets$0 \TO $min(i,k)$} \do 
        \IF {$j=0$ \OR $j=i$}
            \STATE $C[i,j] \gets  1$
        \ELSE
            \STATE $C[i,j] \gets  C[i-1,j-1]+C[i-1,j]$
        \ENDIF
    \ENDFOR
\ENDFOR
\RETURN C[n,k]

\end{algorithmic}

Best Answer

Remove the \dos, and this works fine. As a side note, use $\min(i,k)$ instead of $min(i,k)$, and (as egreg mentioned in a comment) there is a pair of $ missing from the last line of the algorithm.

\documentclass{article}
\usepackage{algorithmic} 
\begin{document}
\begin{algorithmic}
\FOR {$i\gets0$ to $n$} 
    \FOR {$j \gets$0 \TO $\min(i,k)$} 
        \IF {$j=0$ \OR $j=i$}
            \STATE $C[i,j] \gets  1$
        \ELSE
            \STATE $C[i,j] \gets  C[i-1,j-1]+C[i-1,j]$
        \ENDIF
    \ENDFOR
\ENDFOR
\RETURN $C[n,k]$
\end{algorithmic}

\end{document}

enter image description here