Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 998861
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:15:59+00:00 2026-05-16T07:15:59+00:00

Can anyone tell me what exactly happens in a Recursion Program.. ??

  • 0

Can anyone tell me what exactly happens in a Recursion Program.. ??

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T07:16:00+00:00Added an answer on May 16, 2026 at 7:16 am

    A function calls itself over and over, until some condition is met.

    A silly example: How to walk 100 steps recursively:

     function walk(steps) {
         if (steps > 0) { // not there yet
            take 1 step
            walk(steps - 1); // we're 1 step closer, now walk the rest of the way
         } else { // we're there already, don't walk any further than requested
            echo "You're there!"
         }
     }
    
     walk(100); // go!
    

    This is what happens:

     walk(100):
       take 1 step
       walk(99):
         take 1 step
         walk(98):
           take 1 step
           walk(97):
             (...)
                       walk(2):
                         take 1 step
                         walk(1):
                           take 1 step
                           walk(0):
                             // "steps > 0" no longer true, use the "else" branch
                             echo "You're there!"
    

    Note that the same thing could be accomplished with a loop (“iteratively”):

    function walk(steps) {
      for (c=steps; c > 0; c--) { // note the condition check - "c > 0"
        take 1 step
      }
      echo "You're there!"
    }
    
    walk(100); // go!
    

    The program flow would be a bit different, yet the result is the same:

    walk(100):
      c=100
      take 1 step
      c=99
      take 1 step
      c=98
      take 1 step
      (...)
      c=2
      take 1 step
      c=1
      take 1 step
      c=0
      // "c > 0" no longer true, exit loop
      echo "You're there!"
    

    It cannot be said whether recursion or iteration is always better. In this example, iteration (loop) is simpler to write and easier to understand than recursion; in other cases (e.g. traversing tree structures), recursion may be a better solution.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to WPF.. Can anyone tell.. What exactly the depentent properties means?..
can anyone tell what exactly is dynamic casting means in c++. where exactly can
Can anyone tell me what exactly does an array adapter do? I've tried searching
Can anyone please tell me what exactly this script does? #! /bin/sh test –f
Can anyone tell me what exactly does this Java code do? SecureRandom random =
Can anyone tell me what exactly the difference between an completely abstract class and
I'm a newbie in rails.Can anyone tell me what exactly nested attributes are and
Can anyone tell me why this code would not be working? $('body').on('test', function() {
can anyone tell me how to select data by date in MS.ACCESS database using
Can anyone tell me why the following code fails to submit the form into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.