Ad
  • Custom User Avatar

    for recursion, it's important to define the terminating condition if (p0>= p) return 0.
    Note that 0 is an identity value for addition ( 1 + 0 =1).
    It's also important to consider using tail recursion to avoid StackOverflowError
    i.e. 1 + nbYear instead of nbYear + 1
    that way compiler can optimize calls
    e.g (1 + (1 + nbYear)) -> 2 + nbYear
    instead of (nbYear + (nbYear + 1))