[Tex/LaTex] Accessing value in forloop

counterserrorsforeachloops

This code is not compiling and creates an error "Missing number, treated as zero".

\newcounter{x}
\forloop{x}{0}{\value{x} < 5}{
    value is \value{x} \\
}

How can the value of x be printed from inside the for loop?

Best Answer

enter image description here

\documentclass[12pt]{article}
\usepackage{forloop}
\begin{document}

\newcounter{x}
\forloop{x}{0}{\value{x}<5}{\noindent value is \arabic{x}\\}

\end{document}

You can also print the numbers as strings (zero, one, two , ...), if you load the fmtcount package and instead of \arabic{x} you can use \numberstring{x}.

Related Question