Breaking a recursive cycle!

This is a discussion on Breaking a recursive cycle! within the C Programming forums, part of the General Programming Boards category; Any ideea on how to do that? Something like break for a loop....

  1. #1
    Registered User
    Join Date
    Dec 2005
    Posts
    167

    Breaking a recursive cycle!

    Any ideea on how to do that? Something like break for a loop.

  2. #2
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,709
    A recursive function should only be broken when the base condition is met. So in your function you need to have an if test.

  3. #3
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    You could just stop recursing, and the stack would unwind.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  4. #4
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    Yea use a loop with a break statement.

  5. #5
    Its not rocket science vasanth's Avatar
    Join Date
    Jan 2002
    Posts
    1,683
    Code:
     
     
    void recursiveFunction(arguments){
     
    if(conditionMet)
    return;
     
    --- do something----
    recursiveFunction(arguments);
    }

  6. #6
    Registered User
    Join Date
    Apr 2006
    Posts
    6
    You can also use longjmp.

  7. #7
    Registered User
    Join Date
    Dec 2005
    Posts
    167
    longjump ? what's that ?

  8. #8
    Registered User
    Join Date
    Apr 2006
    Posts
    6
    It's like a global goto. I suggested it just as a joke, you shouldn't really use it unless you have to.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. recursive function
    By technosavvy in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 04:42 AM
  2. difference between recursive and iterative
    By Micko in forum C Programming
    Replies: 33
    Last Post: 07-06-2004, 09:34 PM
  3. Algorithm help (Changing from Recursive to Non Recursive)
    By Thantos in forum C++ Programming
    Replies: 1
    Last Post: 04-25-2004, 07:27 PM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 09:33 AM
  5. How to change recursive loop to non recursive loop
    By ooosawaddee3 in forum C Programming
    Replies: 1
    Last Post: 06-24-2002, 08:15 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21