簡體   English   中英

為什么Call語句中的第一個參數沒有用%符號包圍? (批處理文件)

[英]Why the 1st parameter in the Call statement is not surrounded with % sign? (Batch File)

當call語句中的第一個參數沒有用'%'符號包圍時,該批處理文件仍如何工作?

'Number1'變量如何仍獲得值1?

@echo off

set "fst=0"
set "fib=1"
set "limit=1000000000"

致電:myFibo fib,%fst%,%limit%

echo.The next Fibonacci number greater or equal %limit% is %fib%.

echo.&pause&goto:eof


::--------------------------------------------------------
::-- Function section starts below here
::--------------------------------------------------------

:myFibo  -- calculate recursively the next Fibonacci number greater or equal to a limit
::       -- %~1: return variable reference and current Fibonacci number
::       -- %~2: previous value
::       -- %~3: limit
SETLOCAL
set /a "Number1=%~1"
set /a "Number2=%~2"
set /a "Limit=%~3"
set /a "NumberN=Number1 + Number2"

如果/ i%NumberN%LSS%Limit% call:myFibo NumberN,%Number1%,%Limit%

(ENDLOCAL
    IF "%~1" NEQ "" SET "%~1=%NumberN%"
)
goto:eof

使用%1,%2 ..%9訪問傳遞到bat文件或子例程的參數。 有關更多信息的論點 ; 轉移

並且SET /A不需要%括起來來計算變量值。

因此,在您的情況下,Number1獲取第一個參數的值,Number2獲取第二個參數的值,numberN獲取兩個參數的總和.Number1設置為fib,隨后通過SET /A擴展為其可變值

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM