Hey guys,
I'm trying to learn how to use factorials, this is a simple example:
Once i run it i get the desired results, but once stepping through the code i noticed that once the if is done(10 cycles), it loops ending of the function 10 times. And even though it keeps going through the test = test + 1, the value keep refreshing to 0, why is this happening? Is there a way to end all the looped functions at once?
I'm trying to learn how to use factorials, this is a simple example:
Code:
Option Explicit
Function factorials(nr As Long, Optional factorialsTest As Long = 1)
Dim test As Variant
factorialsTest = nr * factorialsTest
nr = nr - 1
If nr <> 0 Then Call factorials(nr, factorialsTest)
test = test + 1
End Function
Sub main()
Dim test As Variant
test = factorials(10)
End Sub
Once i run it i get the desired results, but once stepping through the code i noticed that once the if is done(10 cycles), it loops ending of the function 10 times. And even though it keeps going through the test = test + 1, the value keep refreshing to 0, why is this happening? Is there a way to end all the looped functions at once?
Last edited: