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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T08:41:05+00:00 2026-06-02T08:41:05+00:00

I took a course in C++ where we had some homework to show to

  • 0

I took a course in C++ where we had some homework to show to our teacher, in there were some if statements like this:

if (A != 10)
    return 1;

...snip logic ...
return 12;

He didn’t like this and suggested i’d neste it like this instead, even if there was more than one level of nesting:

if (A == 10) {
    ...snip logic ...
    return 12;
} else
    return 1;

He couldn’t really explain to me why he wanted it like that. So my question is, is there any reason to nestle if statements like that? I think it’s both easier and cleaner to have some conditions in the beginning of my function which return early. Any thoughts or ideas on why one of these ideas is better/faster? Is there any big difference in the compiled code afterwards?

  • 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-02T08:41:07+00:00Added an answer on June 2, 2026 at 8:41 am

    When it comes to coding style you can listen to opinions but it’s best that you make your own style. The first solution looks far cleaner to me, easier to read, but it’s just a matter of taste after all.
    In regard to performance there’s absolutely no difference.

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

Sidebar

Related Questions

Possible Duplicate: Should a function have only one return statement? My teacher took points
I have some controller logic: public function seafood() { $this->set('title', 'Seafood restaurants in and
This semester, I took a course in computer graphics at my University. At the
I took this from another question I had. Under appropriate uses for sqlite it
I took a computer graphics course (graduate level) this past year. We spent the
In an operating systems course I took a while ago we were working on
it took me some time to find out that both Eclipse and Aptana get
I took a look at this answer and it goes in part to solving
I took some code here: Check if role consists of particular user in DB?
I've been revisiting Motorola 68000 programming lately. Admittedly, when I took the course I

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.