Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Why does my Loop end after 11 Loops?
#50
I don't know how things are going for you now. Is this really a recursive processing, or is something just called after a counter?

From Herbert Schildt, C command library, recursion page 102:
When developing recursive functions, there have to be an IF statement somewhere that makes the function return without executing another recursive call. Without this provision, the function never returns after it is called. Writing recursive functions without an IF is a common mistake.

The same program as above, only without the IF. You have to break it off with Strng-C.

Code: (Select All)
$Console:Only
Option _Explicit

Declare Function Fakultaet(n As Integer) As _Integer64

Dim As Integer n

Locate 2, 3
Print "Rekursive Berechnung der Fakultaet - (n!)"

Locate 4, 3
Input "Fakultaet von (n): ", n

Locate 5, 3
Print Using "Die Fakultaet von ### ist: ###,###,###"; n, Fakultaet(n)

End 'Hauptprogramm


Function Fakultaet (n As Integer)

  Dim As _Integer64 fakul

  fakul = Fakultaet(n - 1) * n

  Fakultaet = fakul
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-11-2023, 03:47 PM



Users browsing this thread: 7 Guest(s)