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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T17:17:34+00:00 2026-06-18T17:17:34+00:00

Sorry if the title is rather ambiguous, I was not sure how to word

  • 0

Sorry if the title is rather ambiguous, I was not sure how to word it.

Is it better to phrase a condition such that the outcome you don’t want enters the if statement then you exit the function or should I test for the outcome I do want and follow the statement with my code.

Maybe some examples would help:

What I mean by testing for negative result:

if(myObject == null) {
    return;
}

//do whatever with myObject

What I mean by testing for positive result:

if(myObject != null) {
    //do whatever with myObject
}

Sorry, if someone can word it better than me please do.

  • 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-06-18T17:17:35+00:00Added an answer on June 18, 2026 at 5:17 pm

    I personally prefer the first method of checking if the object is null then immediately returning. It allows the “real code” to stay unindented, linear, and can prevent many nested if statements, which I find to be more readable.
    Otherwise, both ways are valid and will have the same outcome. Choose whichever works best in your situation (which can depend on any else or else if statements).

    Here’s a good example:

    if (object1 == null) {
        return;
    }
    // do some stuff
    if (object2 == null) {
        return;
    }
    // do some stuff
    if (object3 == null) {
        return;
    }
    

    Opposed to:

    if (object1 != null) {
        // do some stuff
        if (object2 != null) {
            // do some stuff
            if (object3 != null) {
                // do some stuff
            }
        }
    }
    

    I find the first one to be much more readable.

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

Sidebar

Related Questions

Sorry about the odd title, I'm not sure how to phrase the question. Basically,
Sorry for the confusing title but I'm not sure how better to explain it.
Sorry for the title.....bit difficult to word what I really want to ask. Some
Sorry if the title is vague - I wasn't quite sure how to word
Sorry for the title, not easy to phrase it correctly. I have a table
Sorry if the title isn't accurate, I am not 100% sure it describes the
Sorry about the title, don't know how to phrase this. I have my own
Sorry my title is rather vague but I don't know how to concisely label
Sorry with title if it is not looks bad, I don't know how can
Sorry about the title of the question, I wasn't sure how to word it

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.