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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T14:49:32+00:00 2026-05-12T14:49:32+00:00

Yes, I know the wording is hard to understand, but this is something that

  • 0

Yes, I know the wording is hard to understand, but this is something that bugs me a lot. On a recent project, I have a function that recurses, and there are a number of conditions that would cause it to stop recursing (at the moment three). Which of the situations would be optional? (I.E. best performance or easiest maintenance).

1) Conditional return:

void myRecursingFunction (int i, int j){
    if (conditionThatWouldStopRecursing) return;
    if (anotherConditionThatWouldStopRecursing) return;
    if (thirdConditionThatWouldStopRecursing) return;

    doSomeCodeHere();
    myRecursingFunction(i + 1, j);
    myRecursingFunction(i, j + 1);
}

2) Wrap the whole thing in an if statement

void myRecursingFunction (int i, int j){
    if (
        !conditionThatWouldStopRecursing &&
        !anotherConditionThatWouldStopRecursing &&
        !thirdConditionThatWouldStopRecursing
    ){
        doSomeCodeHere();
        myRecursingFunction(i + 1, j);
        myRecursingFunction(i, j + 1);
    }
}

3) You’re doing it wrong noob, no sane algorithm would ever use recursion.

  • 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-12T14:49:32+00:00Added an answer on May 12, 2026 at 2:49 pm

    Both of those approaches should result in the same IL code behind the scenes since they are equivalent boolean expressions. Note that each termination condition will be evaluated in the order you write it (since the compiler can’t tell which is most likely), so you will want to put the most common termination condition first.

    Even though structured programming dictates the second approach is better, personally I prefer to code return conditions as a separate block at the top of the recursive method. I find that easier to read and follow (though I am not a fan of returns in random areas of the method body).

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

Sidebar

Related Questions

(Yes I know I can call Java code from Scala; but that is pointless;
Yes I know, this title isn't really helpfull but this is the exact problem.
I have the following code (Yes I know it's quite long winded, but I
First, yes i know this is a big security NONO . But the scenario
I'm working with a large (270+ project) VS.Net solution. Yes, I know this is
Yes I know that it shouldn't be abused and that C# is primariy used
I´m trying to code a tooltip (Yes I know, I have my reasons to
I have an AXIS2/JAX-WS web service using a code first implementation (yes I know,
I am fairly sure that this would not be possible, but just want to
Yes, I know - that question has thousands of answers. please, don't tell me

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.