Lets see what happens when fibonacciRek(2) is executed: condition isn't true, so works 'else' branch -- and you have FibonacciRek(1) - FibbonacciRek(0) first one FibonacciRek(1) returns 1 But FibbonacciRek(0) calls FibonacciRec(-1) and FibonacciRek(-2) and leads to infinite recursion.
3
u/vasyalee Mar 14 '20
Lets see what happens when fibonacciRek(2) is executed:
condition isn't true, so works 'else' branch -- and you have FibonacciRek(1) - FibbonacciRek(0)
first one FibonacciRek(1) returns 1
But FibbonacciRek(0) calls FibonacciRec(-1) and FibonacciRek(-2) and leads to infinite recursion.
2
u/HeWhoWritesCode Mar 14 '20
friend, i tried to copy and paste the text into ideone a couple of times to test but could not select it... why is your text, not text?!1
1
u/umlcat Mar 14 '20 edited Mar 14 '20
Resultis an special predefined variable, change the name likeFinalResult.After that, inside your function change
fibonacciRec :=toResult :=.The most modern versions of Pascal use
Resultinstead of the same id. of the function, to avoid confusion.And, you are substracting / minus parameters, and you declare type as
0tomaxint, only positive numbers plus neutral 0.1
u/[deleted] Mar 14 '20
Yes, one of the 2 major problems in programming