# Why is \IF throwing an error?

I am writing algorithm but it is giving error. Please see the code given below:

\documentclass{beamer}
\usepackage{algorithm,algorithmic}
\begin{document}
\begin{frame}

\begin{algorithmic}
\STATE $S \Leftarrow (u,1);$
\WHILE{$S \neq \phi$}
\STATE $(u,1) \Leftarrow S ;$
\STATE color[$u$] := gray;
\IF{$k \le$ deg$(u)$};
\STATE $S \Leftarrow (u,k+1);$
\ELSE[$N$ ]
\ENDWHILE
\end{algorithmic}

\end{frame}
\end{document}


Question : How to give numbering to each line?

• Can you please make the example into a full (minimal) compilable document? – egreg Nov 18 '17 at 17:46
• You're missing \ENDIF and at least a \STATE between \ELSE and \ENDIF. – egreg Nov 18 '17 at 18:05
• Since you have some responses below that seem to answer your question, please consider marking one of them as ‘Accepted’ by clicking on the tickmark below their vote count (see How do you accept an answer?). This shows which answer helped you most, and it assigns reputation points to the author of the answer (and to you!). It's part of this site's idea to identify good questions and answers through upvotes and acceptance of answers. – user36296 Jan 23 '18 at 17:50

How to give numbering to each line?

Since you're using the algorithmic environment, simply change \begin{algorithmic} to \begin{algorithmic}[1] if you want every single line numbered. Use \begin{algorithmic}[2] if only every second line should be numbered, \begin{algorithmic}[5] if only every fifth line should be numbered, etc.

You also have (at least) three syntax errors in the algorithmic code block: (a) a missing \ENDIF statement, (b) missing instruction(s) under the \ELSE branch, and (c) a spurious ; symbol immediately after \IF{...}.

\documentclass{beamer}
\usepackage{algorithm,algorithmic}
\begin{document}
\begin{frame}

\begin{algorithmic}[2] % number every 2nd line
\STATE $S \Leftarrow (u,1);$
\WHILE{$S \neq \phi$}
\STATE $(u,1) \Leftarrow S ;$
\STATE color[$u$] := gray;
\IF{$k \le$ deg$(u)$}
\STATE $S \Leftarrow (u,k+1);$
\ELSE[$N$]
\STATE something;
\ENDIF
\ENDWHILE
\end{algorithmic}

\end{frame}
\end{document}