So, I have this, that has recursion, (which is a plagiarised version of this code). I reworked it a little bit for own understanding
@echo off
set /A fst=0
set /A fib=1
set /A limit=1000
call :myFibo fib, %fst%, %limit%
echo The next Fibonacci number greater or equal %limit% is %fib%.
exit /B 0
:myFibo
SETLOCAL
    echo begin of funct %1, %2, %3
    set /A Number1=%2
    set /A Number2=%1
    set /A Limit=%3
    set /A NumberN=Number1+Number2
    REM
    if %NumberN% LSS %Limit% call:myFibo NumberN, %Number2%, %Limit%
(
    ENDLOCAL 
    set %1=%NumberN%
)
exit /B 0
that gives following output:
begin of funct fib, 0, 1000
begin of funct NumberN, 1, 1000
begin of funct NumberN, 1, 1000
begin of funct NumberN, 2, 1000
begin of funct NumberN, 3, 1000
begin of funct NumberN, 5, 1000
begin of funct NumberN, 8, 1000
begin of funct NumberN, 13, 1000
begin of funct NumberN, 21, 1000
begin of funct NumberN, 34, 1000
begin of funct NumberN, 55, 1000
begin of funct NumberN, 89, 1000
begin of funct NumberN, 144, 1000
begin of funct NumberN, 233, 1000
begin of funct NumberN, 377, 1000
begin of funct NumberN, 610, 1000
The next Fibonacci number greater or equal 1000 is 1597.
There is a couple of things I don't understand:
- why fib and NumberN variables are passed without %% and are treated as strings when I echo them?
- what is the purpose of parentheses around ENDLOCAL and set?
- As of my understanding NumberN variable should be undefined after ENDLOCAL, but it still can be used
 
    