@ECHO OFF IF "%1"=="" ( ECHO Usage: ! [1-12] GOTO :EOF ) :: For any given recursion, you have to have an end, where it begins to return :: This is the 'bottom' of the recursion (similar to a do-while-loop) IF "%1"=="0" ( SET TOTAL=1 Echo. %INDENT% ========== ECHO. %INDENT% seed = 1 Goto :EOF ) :: Descending. Some recursions work on the way down, some on the way up :: This one only counts, on the way down - partly because it's easier to seed :: The total with 1 at that point, than try to create a mechanism to store the :: number you enter, but not store any of the other numbers on the way down. :: From the side, a recursion is similar to dropping objects as you walk :: through a maze, and picking them back up as you retrace your steps. :: Make this visual Echo. %INDENT%Ú Count = %1 :: /a = do arithmetic Set /a COUNT=%1-1 :: Build connecting lines, as we go (SET INDENT=%~2³) :: Recurse - ie, have the function call itself for the next step. CALL !.bat %COUNT% "%INDENT%" :: Ascending. As each functin call returns, it will daisy-chain back up :: the way it descended, and do the last half of each function call as it goes. :: This is the single functional line of the function. Set /a TOTAL=%TOTAL% * %1 :: indent=Mid$(indent,2) SET INDENT=%INDENT:~1% :: Make it visual Echo. %INDENT%À * %1 = %TOTAL%