Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
42
Task/Anonymous-recursion/FreeBASIC/anonymous-recursion.basic
Normal file
42
Task/Anonymous-recursion/FreeBASIC/anonymous-recursion.basic
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
' FB 1.05.0 Win64
|
||||
|
||||
#Lang "fblite"
|
||||
|
||||
Option Gosub '' enables Gosub to be used
|
||||
|
||||
' Using gosub to simulate a nested function
|
||||
Function fib(n As UInteger) As UInteger
|
||||
Gosub nestedFib
|
||||
Exit Function
|
||||
|
||||
nestedFib:
|
||||
fib = IIf(n < 2, n, fib(n - 1) + fib(n - 2))
|
||||
Return
|
||||
End Function
|
||||
|
||||
' This function simulates (rather messily) gosub by using 2 gotos and would therefore work
|
||||
' even in the default dialect
|
||||
Function fib2(n As UInteger) As UInteger
|
||||
Goto nestedFib
|
||||
|
||||
exitFib:
|
||||
Exit Function
|
||||
|
||||
nestedFib:
|
||||
fib2 = IIf(n < 2, n, fib2(n - 1) + fib2(n - 2))
|
||||
Goto exitFib
|
||||
End Function
|
||||
|
||||
For i As Integer = 1 To 12
|
||||
Print fib(i); " ";
|
||||
Next
|
||||
|
||||
Print
|
||||
|
||||
For j As Integer = 1 To 12
|
||||
Print fib2(j); " ";
|
||||
Next
|
||||
|
||||
Print
|
||||
Print "Press any key to quit"
|
||||
Sleep
|
||||
Loading…
Add table
Add a link
Reference in a new issue