# Undefined control sequence \WHILE

I get a Undefined control sequence \WHILE error in my latex code.

\documentclass[11pt]{article}
\usepackage{algorithm}
\usepackage{algorithmicx}
\begin{document}
\begin{algorithm}
\begin{algorithmic}
$\bar{w} \leftarrow w.$

$S = \{u \in V : w(u) = 0 \}$.
$\WHILE{S is not a hitting set for C} do \mathcal{M}$  a collection of cycles returned by a violation oracle Violation(G, C, S).
$c_{ \mathcal{M} (u) } \leftarrow |{M _ M : u _ M}|, for all u _ V$.
$\alpha \leftarrow min_ {u \in V \backslash S} | w(u) / c_{M (u) }$
$\bar{ w(u) } \leftarrow w(u) - \alpha cM (u),$ for all u in V.
$S \leftarrow \{u _ V : w(u) = 0 \}. \ENDWHILE$
%end
return a minimal hitting set $H \subset S$ of $\mathcal{C}$.
\end{algorithmic}
\end{algorithm}
\end{document}


Also I'm a bit confused about the various algorithms packages and which can be used together

• First of, the while should not be n math mode and it should be While not WHILE. See the manual for reference Apr 20 '18 at 15:54
• but capital \While appears in en.wikibooks.org/wiki/LaTeX/… also I've tried doing it not in mathmode still doesn't work Apr 20 '18 at 18:00
• I guess you're correct, but do take the example from that page and adapt it, basically most of what you are doing here is wrong, a lot of stuff that should not be in math mode and a lot of stuff that should be in math mode. Also please make this example complete, there is no preamble, when people have to guess code in order to help, they are much less likely to bother helping Apr 20 '18 at 18:06
• If you look at the wiki every line starts with a statement, an algorithm is actually a sort of list, thus the very first line you use is wrong as it is not a statement. Otherwise look in the manual linked to from the wiki Apr 20 '18 at 18:09
• sorry I don't understand your comment daleif what is wrong with the first line? also I've deleted the first line and it still doesn't work Apr 21 '18 at 16:02

This example works (not sure if I formatted it correctly).

\documentclass[11pt]{article}
\usepackage{algorithm}
\usepackage{algorithmic}
\begin{document}
\begin{algorithm}
\begin{algorithmic}
\STATE $\bar{w} \leftarrow w.$
\STATE $S = \{u \in V : w(u) = 0 \}$.
\WHILE{$S$ is not a hitting set for $C$}
\STATE $\mathcal{M}$  a collection of cycles returned by a violation oracle Violation(G, C, S).
\STATE $c_{ \mathcal{M} (u) } \leftarrow |{M _ M : u _ M}|, for all u _ V$.
\STATE $\alpha \leftarrow min_ {u \in V \backslash S} | w(u) / c_{M (u) }$
\STATE $\bar{ w(u) } \leftarrow w(u) - \alpha cM (u),$ for all u in V.
\STATE $S \leftarrow \{u _ V : w(u) = 0 \}$.
\ENDWHILE
\RETURN a minimal hitting set $H \subset S$ of $\mathcal{C}$.
\end{algorithmic}
\end{algorithm}
\end{document}


The WIKI page you refer to is rather hard to read, it is not clear which pseudocode package is used where, and they do not use the same syntax (that's why I reacted on \WHILE and thought is was spelled differently (not all upper case). The syntax the same use is from algorithmic not why one you're trying to use.

• @HaoS Problem solved? Apr 1 '20 at 19:25