I enjoy your inquisitive mind.
Gremlins have taken over your machine and caused it to start counting backwards.
Just kidding. =)
Actually, it seems like a textbook example of recursion. You initially call the function Test with a parameter of 0. The meat of the function is essentially a statement that adds 1 to Parm. After that, it reaches a base case test. The test is whether Parm + 1 >= 10. If it not, then the function calls itself with Parm + 1 as the new parameter. A copy of the variable scope (parm, test#) gets placed on the (function call) stack, and the new iteration of Test#(parm) begins. This repeats until Parm + 1 = 10. At this point, there are 10 function calls on the stack to Test#(), each with different variable scopes. Finally, a Return statement is reached, and so "10.0" is finally returned as the evaluated part of the Print statement, and is indeed printed. It isn't until this (the 9th) call of Test that it actually reaches the "end function" statement for the first time. This continues, each function recursively popping off the stack, until you're left with the original call, which returns 1, and happily prints it. The final print is 0 (test#=0), because it is outside of the function scope.
Note that the more you do this, the more memory is used to keep track of the function call stack. Large, hungry recursive functions have been known to bring systems to their knees, which is why most programmers prefer the iterative version of a function, rather than the recursive function, unless it is a particularly elegant solution.
One of the reasons this works is because it relies on the local scope of the function. Try declaring Test# as a global and see what happens. =)
Gremlins have taken over your machine and caused it to start counting backwards.
Just kidding. =)
Actually, it seems like a textbook example of recursion. You initially call the function Test with a parameter of 0. The meat of the function is essentially a statement that adds 1 to Parm. After that, it reaches a base case test. The test is whether Parm + 1 >= 10. If it not, then the function calls itself with Parm + 1 as the new parameter. A copy of the variable scope (parm, test#) gets placed on the (function call) stack, and the new iteration of Test#(parm) begins. This repeats until Parm + 1 = 10. At this point, there are 10 function calls on the stack to Test#(), each with different variable scopes. Finally, a Return statement is reached, and so "10.0" is finally returned as the evaluated part of the Print statement, and is indeed printed. It isn't until this (the 9th) call of Test that it actually reaches the "end function" statement for the first time. This continues, each function recursively popping off the stack, until you're left with the original call, which returns 1, and happily prints it. The final print is 0 (test#=0), because it is outside of the function scope.
Note that the more you do this, the more memory is used to keep track of the function call stack. Large, hungry recursive functions have been known to bring systems to their knees, which is why most programmers prefer the iterative version of a function, rather than the recursive function, unless it is a particularly elegant solution.
One of the reasons this works is because it relies on the local scope of the function. Try declaring Test# as a global and see what happens. =)