This shows one way how to use a nested loop with etoolbox
\forlistloop has two parameters: The second one is the list name, the first one is a list processor, i.e. what is to be done inside the loop.
The best idea is to use a \newcommand macro which is expandable.
This list processing macro can have a 'arbitrary' number of arguments, but the last one is always used to handle of the current list element, which is determined by \forlistloop.
In a nested \forlistloop approach, this requires for example two list processors macros. The outer one uses the internal \forlistloop and the internal \grabfrominnerlist macro.
Please note, that there is no general rule how to do nested looping -- the typesetting determines the nesting/looping order (amongst other TeX specific features such as grouping etc.)
\documentclass{article}
\usepackage{etoolbox}
\newcounter{rowcounter}
\newcounter{columncounter}
\newcounter{innercounter}
\newcommand{\addwithcounting}[3]{%
\stepcounter{#1}
\listadd{#2}{#3}
}
\newcommand{\grabfromouterlist}[2]{%
\setcounter{innercounter}{0}% Reset the inner counter
\forlistloop{\grabfrominnerlist{#2}}{#1} \\ % use the 2nd argument which is fed from the outer loop actually and process the list given as 1st argument.
}
\newcommand{\grabfrominnerlist}[2]{%
\stepcounter{innercounter}%
\ifnumless{\value{innercounter}}{\value{columncounter}}{%
a_{#1#2} & % typeset the matrix element with index of row and column number
}{%
a_{#1#2}% Final column, do not add a & character
}%
}
\usepackage{mathtools}
\begin{document}
\def\mycolumnlist{}
\def\myrowlist{}
\forcsvlist{\addwithcounting{rowcounter}{\myrowlist}}{1,2,3,4,5,6,7,8,9}
\forcsvlist{\addwithcounting{columncounter}{\mycolumnlist}}{1,2,3,4,5,6,7,8}
$\begin{pmatrix}
\forlistloop{\grabfromouterlist{\mycolumnlist}}{\myrowlist}
\end{pmatrix}$
$\begin{Bmatrix}
\forlistloop{\grabfromouterlist{\mycolumnlist}}{\myrowlist}
\end{Bmatrix}$
\end{document}

Please note that you can't use more than 10 columns here (without some more work), but this not a problem of etoolbox but of the underlying matrix environment.
Edit
The O.P. sent me a mail with some questions, so I'll try to answer here with some 'extended' version.
The \forlistloop command has two arguments: The first one is the list processing one, the second is the command sequence for the list.
\forlistloop does nothing more (but not less too) than to sweep through the list elements, cracking the list into its list elements. During the sweep this element is given to the list processing macro as the last argument. So, for example, if the list should just be shown, a processor naming \showlist would be sufficient.
\newcommand{\showlist}[1]{%
#1 % <---- this is handled over by \forlistloop
}
\forlistloop{\showlist}{\mylist} % Does the job
Now, the list processor can have of course more than just argument, but the data from the list always enters from the right to the left side, so it's always the last argument that gets the list element from \forlistloop or \forlistcsloop.
The command call \forlistloop{\grabfromouterlist{\mycolumnlist}}{\myrowlist} will loop through the \myrowlist content, i.e. the row number here in the example.
This row number,say 8, is fed to \grabfromouterlist{\mycolumnlist}{8} then etc. Since \grabfromouterlist itself uses \grabfrominnerlist, this will loop through \mycolumnlist and use the number 8 effectively etc.
\documentclass{article}
\usepackage{etoolbox}
\newcounter{rowcounter}
\newcounter{columncounter}
\newcounter{innercounter}
\newcommand{\addwithcounting}[3]{%
\stepcounter{#1}
\listadd{#2}{#3}
}
\newcommand{\grabfromouterlist}[3][a]{%
\setcounter{innercounter}{0}% Reset the inner counter
\forlistloop{\grabfrominnerlist[#1]{#3}}{#2} \\ % use the 2nd argument which is fed from the outer loop actually and process the list given as 1st argument.
}
\newcommand{\grabfrominnerlist}[3][a]{%
\stepcounter{innercounter}%
\ifnumless{\value{innercounter}}{\value{columncounter}}{%
#1_{#2#3} & % typeset the matrix element with index of row and column number
}{%
#1_{#2#3}% Final column, do not add a & character
}%
}
\usepackage{mathtools}
\begin{document}
\def\mycolumnlist{}
\def\myrowlist{}
\forcsvlist{\addwithcounting{rowcounter}{\myrowlist}}{1,2,3,4,5,6,7,8,9}
\forcsvlist{\addwithcounting{columncounter}{\mycolumnlist}}{1,2,3,4,5,6,7,8}
$\begin{pmatrix}
\forlistloop{\grabfromouterlist[b]{\mycolumnlist}}{\myrowlist}
\end{pmatrix}$
$\begin{Bmatrix}
\forlistloop{\grabfromouterlist{\mycolumnlist}}{\myrowlist}
\end{Bmatrix}$
$\begin{Bmatrix}
\forlistloop{\grabfromouterlist[\sum]{\mycolumnlist}}{\myrowlist}
\end{Bmatrix}$
\end{document}

Please note the use of the optional first argument, which defaults to a. This information has to be given on the outermost left side, as first parameter.
\dolistloopapproach requires a redefined\docommand. – Jul 21 '15 at 06:11\foreachforpgfforpackage could be easier by far, but this depends on the requirements – Jul 21 '15 at 06:18minimaldocument class is not meant for the end-user. Have a look at http://tex.stackexchange.com/questions/42114/why-should-the-minimal-class-be-avoided – percusse Jul 21 '15 at 06:22