DOS批处理 函数定义与用法
What it is, why it`s important and how to write your own.Description: The assumption is: A batch script snippet can be named a function when:1.... it has a callable entrance point.The benefits behind functions are:1.Keep the main script cleanCreate a Function - What is a functionCall a Function - How to invoke a functionExample - Calling a Function - An Example showing how it works1.The main script: starting at line 1 ending with a GOTO:EOF command that terminates the script.Note: The last call to myDosFunc doesn`t use double quotes for the second argument. Subsequently "for" and "me" will be handled as two separate arguments, whereas the third argument "me" is not being used within the function. Returning Values the Classic Way - The classic way of returning values and the limitationsNote: The var1 variable is reserved for this particular function. Any data stored in var1 by the calling function before calling :myGetVar will be overwritten. Note: The var1 variable is not reserved for this articular function. Any variable can be passed to the function the caller has full control. Local Variables in Functions - How to avoid name conflicts and keep variable changes local to the functionRecursive Functions - Tadaaah!!!Example: The next example below shows how to calculate a Fibonacci number recursively. The recursion ss when the Fibonacci algorism reaches a number greater or equal to a given input number. The first argument of the myFibo function is the name of the variable to store the output in. This variable must be initialized to the Fibonacci number to start with and will be used as current Fibonacci number when calling the function and will be set to the subsequent Fibonacci number when the function returns. 出处: