# Insert loop inside table?

1- I want to make a table with n number of rows ?

my wrong code

\newcommand{\xx}{
\begin{tabular}{|c|c|c|}
\hline

\newcount\fooo
\fooo=10
\loop

11 & 12 & 13\\
\hline

\ifnum \fooo>0
\repeat

\end{tabular}
}


I want the result like that using loop or any command

2- \def\abc{dd} create one value

I want command create multiple values

like \def-multiple \abc {dd,cc,vv,mm}

now i am using this code

\foreach \x in {1,...,\nRows} {\addtabtoks{ \abc(\x) & yyy & yyy \\\hline}}

the desired command is \abc(\x) or \abc(2) first loop type the first value of \abc second loop type the second value of \abc and so on

The table is implemented by \halign primitive where groups are allocated in cells, expansion process and scanning parameters of macros is somewhat more complicated in order to coordinate them with replacing declaration data for cells. This is reason why it is no good idea to do calculations and complicated macro expansion inside and across cells. It is possible but you have to know \halign behavior in detail and you need to know exactly what you and TeX are doing.

But more simple solution is possible. You can prepare \tabledata before table is processed. This work:

\documentclass[12pt]{article}

\newcount\fooo

\begin{document}

\def\tabledata{} \fooo=10
\loop
\hline}
\ifnum \fooo>0
\repeat

\begin{tabular}{|c|c|c|}
\hline
\tabledata
\end{tabular}

\end{document}


When you need to insert something what depends on the loop variable, then you have to expand it inside the loop. But other fragile macros cannot be expanded. For example you need to insert the value of loop variable. Then you can do it by this:

   \edef\tabline{\the\fooo & 12 & 13}


This is a LaTeX solution, with a \forloop from forloop package. It builds a tabular array with a command \maketablerows{number_of_rows}{rowcontent}, where rowcontent is suspected to hold the values for the cells in a row, either direct or via a command.

\documentclass[paper=a4,12pt]{scrbook}

\usepackage{forloop}%
\usepackage{etoolbox}%

\begin{document}

\makeatletter
\newcounter{column@@counter}
\newcounter{row@@counter}

\newcounter{inner@@counter}%

\edef\t@@blerow{}%
\edef\t@@blerowtemp{}%

\newrobustcmd{\singletablerow}[3]{%
#1  & #2 & #3
}%

\newrobustcmd{\maketablerows}[2]{%
\setcounter{row@@counter}{0}%
\forloop{row@@counter}{0}{\number\value{row@@counter} < #1}{%
\setcounter{inner@@counter}{\number\value{row@@counter}}%
\stepcounter{inner@@counter}%
\ifnumequal{\number\value{inner@@counter}}{#1}{%
#2%
}{%
#2 \tabularnewline%
%\hline
}%
}%
}%

\begin{tabular}{lll}
%\hline%
\maketablerows{10}{\singletablerow{11}{12}{13}}%
\tabularnewline%
%\hline%
\end{tabular}

\makeatother

\end{document}