# Missing number, treated as zero for a \loop … \repeat

I'm trying to write simple macros, which functional is to print every n = n + k-th letter from the alphabet, where k and n are counters. So I need a \loop-\repeat construction. I use it, but it works incorrectly unfortunately.

The main error is "missing number, treated as zero" in row with a \repeat command written. I also tried without using the \value{n} function - the same result.

Any ideas how to fix it to work fine?

Here is my code:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[english, russian]{babel}
\usepackage{amsmath}
\begin{document}
\newcounter{n}
\newcounter{k}
\setcounter{k}{1}
\setcounter{n}{0}
\loop
\alph{ \value{n} }
\ifnum \value{n} < 26 \repeat
\end{document}


You use \value at the wrong place. You need to use it in the second argument of \addtocounter rather than in \alph. (I commented out the packages that are not directly related to the problem.)

\documentclass{article}
% \usepackage[utf8]{inputenc}
% \usepackage[english, russian]{babel}
% \usepackage{amsmath}
\begin{document}
\newcounter{n}
\newcounter{k}
\setcounter{k}{1}
\setcounter{n}{0}
\loop
\alph{n}
\ifnum \value{n} < 26 \repeat

Or without spurious spaces:
\setcounter{n}{0}%
\loop%
\alph{n}%
\ifnum\value{n}<26\repeat
\end{document}


The command \alph takes as argument a counter's name, so \alph{\value{n}} is incorrect and should be \alph{n}.

The command \addtocounter takes two arguments; the first argument is the name of the counter LaTeX should act on, the second argument should be an integer (in any possible denotation); if you want to increment counter n by 31, you can do

\addtocounter{n}{31}


provided mycounter currently stores 31. The second argument cannot contain just a counter's name.

So you have two calls wrong: \alph{\value{n}} (watch out for spaces) should be \alph{n}, whereas \addtocounter{n}{k} should be \addtocounter{n}{\value{k}}.

You also have spurious spaces and the order wrong (you won't get z):

\setcounter{k}{1}
\setcounter{n}{0}

\loop
\ifnum\value{n} < 26