Is there a command that creates a counter or, if it already exists, redefines it? Thing is that I'm working with nested loops. The second loop is however in a command. This means if I want to use a second counter for the second loop, I need to define it before the first loop and give it as an argument in the command which seems a bit cumbersome.
As example:
\newcommand\recursiveloop[2]{% do loop with counter #2, #1 times
\setcounter{#2}{0}
{\loop\unless\ifnum\value{#2}=#1
\stepcounter{#2}
% do something
\repeat}
}
\newcounter{loop} % counter for first loop
\newcounter{recloop} % counter for recursive loop
\loop\unless\ifnum\theloop=4 % start the first loop
\stepcounter{loop} % counter loop +1
% do something
\recursiveloop{3}{recloop} % call command to run second loop
\repeat
In this example it's of course not a big deal. But my command has already 3 arguments and more will be added.. Isn't there a way of (1) check if the counter exists to run the appropriate command: \setcounter
or \newcounter
or (2) a command that can do it by himself.