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 6892965
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:36:00+00:00 2026-05-27T06:36:00+00:00

I was wondering if something like this could be used in code. If I

  • 0

I was wondering if something like this could be used in code.
If I had a block of code I wanted to execute that was the same at many parts of the program
and it used this version of the while loop, would this work?
(I am aware that I could use a while loop, I just thought this would be an interesting idea to explore)

NSMutableArray *objects;
-(void) RemoveObjectLoop
{
    [self RemoveObjectAtZero];
}

-(void) RemoveObjectAtZero
{
    if([objects count] > 0)
    {
        [objects removeObjectAtIndex:0];
        [self RemoveObjectLoop];
    }
}

Instead of writing out a while loop multiple times just do [self RemoveObjectLoop].
Could this work for a project?
Is there any instance where you wouldn’t want to use this?

Edit: I know this example is bad, I just couldn’t think of anything else.
If you could, please include an example in your answer. Thanks!

  • 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-27T06:36:00+00:00Added an answer on May 27, 2026 at 6:36 am

    In recursion you normally wouldn’t have a circular function call like that. The function would just call itself while working toward a conclusion. So your example would become:

    -(void) RemoveAll
    {
        if([objects count] > 0)
        {
            [objects removeObjectAtIndex:0];
            [self RemoveAll];
        }
    }
    

    Some languages (like Logo) will automatically optimize tail recursion (where the recursive call is the last line of the function). I’ve never heard of Objective-C doing that and I’d be surprised if it did.

    Usually (your question being a case in point as you’ve noted) recursion examples are contrived and would be better solved non-recursively. Here are some real-world examples of recursion.

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

Sidebar

Related Questions

I use a pattern that looks something like this often. I'm wondering if this
I'm wondering whether something like this is possible (and relatively easy to do), and
Came across something like this today, and was wondering if there was an equivalent
I was wondering if it is possible to do something like this: <uc1:TestControl ID=TestControl1
When validating URLs, I was wondering if the root could be setup like this:
I'm exploring the power of regular expressions, so I'm just wondering if something like
I'm wondering if there is something like Hotswap/HotDelpoy/JRebel (known from Java World) in .NET
I am wondering - What's the most effective way of parsing something like: {{HEADER}}
I'm wondering if I'm missing something about Java Beans. I like my objects to
In a jquery plugin options you often see true and false used like this:

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.