Solution 1:

You may use pgffor package, a tool provided by pgf. The basic syntax is:

\foreach \n in {0,...,22}{do something}

Notably, this for loop is not restricted to integers, for example:

\foreach \n in {apples,burgers,cake}{Let's eat \n.\par}

Solution 2:

Something like this will take care of the body of your tabular:

\newcounter{themenumber}
\newcounter{classnumber}
\newcounter{imagenumber}
\forloop{themenumber}{1}{\value{themenumber} < 24}{
    % \hline <-- Error here
    \arabic{themenumber}
    \forloop{classnumber}{0}{\value{classnumber} < 2}{
        \forloop{imagenumber}{1}{\value{imagenumber} < 6}{
            & \includegraphics[scale=2]{
                ../../results/\arabic{themenumber}/\arabic{classnumber}_\arabic{imagenumber}.eps
            }
        }
    }
    \\
    \hline
}

I had to comment out the first \hline because it gave me an error:

You can't use `\hrule' here except with leaders.

I'm not sure what that means; if you really cannot live without the double line, I can look into it more.

Also note that you have to use <; for example, <= 24 will not work.


As to your update: I would simply declare a command that takes the argument that you're looping over. Something like this:

\newcommand\fordir[1]{do something complex involving directory named #1}

\fordir{dira}
\fordir{dirb}
\fordir{dirc}
\dots