Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Why does my Loop end after 11 Loops?
#42
Quote:@Dimster - Is there a reset back to zero for all Recursive calls as a normal use of Recursion . . .


Not that I know. The classic example of a recursion is the determination of the Fibonacci number.

As to the result: In Wikipedia (German), the zero is not taken into account. On the other hand, I orientated myself on the Matheduden.

Code: (Select All)
$Console:Only

Option _Explicit

Declare Function Fibonacci(eingabe As Integer) As _Integer64

Dim As Integer eingabe

Locate 2, 3
Print "Rekursive Berechnung der Fibonaccizahl"

Locate 4, 3
Input "Ihre Eingabe: ", eingabe

Locate 6, 3
Print Using "Die Fibonaccizahl von ### ist: #######"; eingabe, Fibonacci(eingabe)

'Fuer -Press Any Key-
Locate 10, 1

End


Function Fibonacci (eingabe As Integer)

  Dim fibonaccizahl As _Integer64

  If eingabe = 0 Or eingabe = 1 Then
    Fibonacci = 1
  Else
    fibonaccizahl = Fibonacci(eingabe - 1) + Fibonacci(eingabe - 2)
    Fibonacci = fibonaccizahl
  End If

End Function
Reply


Messages In This Thread
Why does my Loop end after 11 Loops? - by Dimster - 02-06-2023, 07:08 PM
RE: Why does my Loop end after 11 Loops? - by Kernelpanic - 02-08-2023, 05:36 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Exiting sub while inside a loop PhilOfPerth 5 525 12-05-2025, 09:40 AM
Last Post: PhilOfPerth
  Do Loop, Sleep and Mouse Button Dimster 5 599 09-06-2025, 12:57 PM
Last Post: Dimster
  Using modulo to loop through lists fistfullofnails 3 723 09-03-2025, 11:50 PM
Last Post: fistfullofnails
  What is wrong with this for/next loop Helium5793 6 1,150 04-15-2025, 05:11 PM
Last Post: Kernelpanic
  Question on ln in a for/next loop Dimster 13 2,248 09-13-2024, 11:07 PM
Last Post: Kernelpanic

Forum Jump:


Users browsing this thread: 1 Guest(s)