Results 1 to 3 of 3

Thread: recursion

  1. #1
    Join Date
    Sep 2004
    Posts
    8

    Unhappy Unanswered: recursion

    is it ok to use recursive function from with in a loop?

  2. #2
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    What would constitute "Ok" in this case?

    Will the compiler allow you to call a recursive function from within a loop? Certainly. The compiler doesn't have any clue that a function is recursive, and really doesn't care either.

    Will the person doing the code review permit a call to a recursive function? They ought to, but that doesn't mean that they will.

    -PatP

  3. #3
    Join Date
    Oct 2003
    Posts
    706
    Many algorithms are "naturally recursive" and are implemented by recursive calls that occur within a loop.

    There is no, "absolute, right-or-wrong, 'OK or not OK'" to be found anywhere in computer programming ... unless you are a pundit selling books and seminars!

    What matters most is that your code is clear. That it is easy to understand what your code is doing and why. That it is easy to verify that your recursive code won't "recurse forever." That your algorithm is efficient and appropriate.

    And... well-documented! "Use comments, dammit!"
    ChimneySweep(R): fast, automatic
    table repair at a click of the
    mouse! http://www.sundialservices.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •