A simple loop in expl3
. In the final argument to \makeloop
you specify the loop template, with #1
standing for the current loop value.
\begin{filecontents*}{\jobname-a1.tex}
aaa1
\end{filecontents*}
\begin{filecontents*}{\jobname-b1.tex}
bbb1
\end{filecontents*}
\begin{filecontents*}{\jobname-a2.tex}
aaa2
\end{filecontents*}
\begin{filecontents*}{\jobname-b2.tex}
bbb2
\end{filecontents*}
\begin{filecontents*}{\jobname-a3.tex}
aaa3
\end{filecontents*}
\begin{filecontents*}{\jobname-b3.tex}
bbb3
\end{filecontents*}
\begin{filecontents*}{\jobname-a4.tex}
aaa4
\end{filecontents*}
\begin{filecontents*}{\jobname-b4.tex}
bbb4
\end{filecontents*}
\documentclass{article}
\usepackage{xparse}
\ExplSyntaxOn
\NewDocumentCommand{\makeloop}{O{1}mm}
{
\cs_gset:Nn \__rashid_loop_temp:n { #3 }
\int_step_function:nnN { #1 } { #2 } \__rashid_loop_temp:n
}
\ExplSyntaxOff
\begin{document}
\begin{tabular}{ll}
\makeloop{4}{\input{\jobname-a#1}\unskip & \input{\jobname-b#1}\unskip \\}
\end{tabular}
\bigskip
\begin{tabular}{ll}
aaa1 & bbb1 \\
aaa2 & bbb2 \\
aaa3 & bbb3 \\
aaa4 & bbb4 \\
\end{tabular}
\end{document}
I used \jobname
just not to clobber my files.
Note \unskip
to remove the space inserted by \input
(the second table is for a check).
The \makeloop
command has an optional argument for specifying a different starting point: \makeloop[4]{7}{...}
would make a loop with values 4,5,6,7.