Function qt

Started by Frank Brübach, April 02, 2024, 08:25:04 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Frank Brübach

Hi all hi Charles

IS this Kind of function structure possible in oxygen?



Function factorial(x As Integer) As Integer
    ' This is a recursive function
    ' to find the factorial of an integer

    If x = 1 Then
        factorial = 1
    Else
        'factorial = x * factorial(x - 1)
        return x * factorial(x-1) 
    End If
End Function

print factorial(2)

Dim num As Integer
    num = 3

Print "The factorial of " + num  + " is "  ''+ str(factorial(num) )

Charles Pegge

Almost:

Function factorial(x As Integer) As Integer
    ' This is a recursive function
    ' to find the factorial of an integer

    If x <= 1 Then
        return 1
    Else
        'factorial = x * factorial(x - 1)
        return x * factorial(x-1)
    End If
End Function

print factorial(4) '24