I am curious to know why the following failed. A similar thread is on comp.text.tex unanswered. Of course, other manipulations of \whileexpr
work, but why does this fail?
\documentclass{article}
\makeatletter
\def\whileexpr#1\do#2{%
#1#2\expandafter\@iden\else\expandafter\@gobble\fi
{\whileexpr#1\do{#2}}%
}
\newcount\colnum
\newcommand\generaterow[2]{%
\colnum\z@
\whileexpr\ifnum\colnum<#2\relax\do{%
#1\advance\colnum\@ne\the\colnum\relax
}%
}
\makeatother
\begin{document}
% Test (worked):
\generaterow{x}{3}% -> x1x2x3
% Failed:
\begin{tabular}{|*{4}{c|}}
\hline
x\generaterow{&}{3}\\\hline
\end{tabular}
\end{document}