# How to programmatically make tabular rows using \whiledo ?

The following code snippet does not work:

\documentclass{minimal}
\usepackage{longtable}
\usepackage{ifthen}
\newcounter{xyz}
\setcounter{xyz}{0}

\begin{document}

\begin{longtable}{|*2{c|}}
\hline
\whiledo{\value{xyz}<10}%
{%
\thexyz & something\stepcounter{xyz} \\\hline%
}%
\end{longtable}
\end{document}

-

\documentclass{article}

\usepackage{longtable}
\newcounter{xyz}\newcounter{uvw}

\makeatletter
\newtoks\@tabtoks
\newcommand*\resettabtoks{\@tabtoks{}}
\newcommand*\printtabtoks{\the\@tabtoks}
\makeatother

\pagestyle{empty}
\begin{document}

\resettabtoks
\loop\ifnum\theuvw<10\relax
\stepcounter{uvw}
\repeat
\begin{longtable}{|*2{c|}}\hline
\printtabtoks
\end{longtable}

\end{document}

-
thanks for the solution. This solution is also informative that lets me know the plain tex. –  xport Dec 23 '10 at 7:04

Try this:

\documentclass{article}
\usepackage{longtable}
\usepackage{ifthen, xspace}
\newcounter{xyz}
\setcounter{xyz}{0}

\begin{document}
\def\and{&\xspace}
\begin{longtable}{|*2{c|}}
\hline
\whiledo{\value{xyz}<10}%
{%
\thexyz \and something\stepcounter{xyz} \\\hline%
}%
\end{longtable}
\end{document}


Edit Changed from minimal class to article (see comments).

-
I don't think that's the right way to do things. I'm not sure exactly what's going on here, but the rules don't appear so something fishy is going on. –  TH. Dec 22 '10 at 19:27
thanks for answering. I got a result without horizontal and vertical tabular rules after compiling your code. –  xport Dec 23 '10 at 0:03
@xport: changing the class to article solves the problem (although I don't know why). –  Bruno Le Floch Mar 7 '11 at 20:33
@Bruno It puzzled me ever since! –  Yiannis Lazarides Mar 7 '11 at 23:25
@Forgiver Yes, it was due to the OP having used the minimal class. There was a follow up question by Bruno, will find it out a bit later and post the link. –  Yiannis Lazarides Jun 7 '12 at 15:57
show 1 more comment