I want to print the numbers 0,1,...,n-1 in a tabular environment. My first attempt resulted in the error Incomplete \iffalse; all text was ignored after line 19.. By "hiding" & (ampersand) in a construct solves the problem. But this looks ugly. Is there a nice way to be able to use \whiledo{}{} programming in a tabular?
Here is my code:
\documentclass{article}
\usepackage{ifthen,calc}
\newcounter{x}
\newcommand{\ampersand}{\ifthenelse{0<1}{&}{}}
\newcommand{\numbers}[1]{\begin{tabular}{|c@{x=}|*{#1}{r|}}
\hline\setcounter{x}{0}
%
% my first attempt produces error:
%
\whiledo{\thex<#1}{&\thex\stepcounter{x}}\\
%
% no error if above line is replaced with:
%
% \whiledo{\thex<#1}{\ampersand\thex\stepcounter{x}}\\
%
\hline\end{tabular}}
\begin{document}\numbers{10}\end{document}

