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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T21:51:40+00:00 2026-06-05T21:51:40+00:00

Is it generally better/faster to do: if (condition) return a else if (condition2) return

  • 0

Is it generally better/faster to do:

if (condition) return a
else if (condition2) return b
else return c

or

if (condition) return a
if (condition2) return b
return c

They both do the same thing but I am curious if there are other ramifications that need to be kept in mind when comparing these two snippets

  • 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-05T21:51:42+00:00Added an answer on June 5, 2026 at 9:51 pm

    Since there is always the same amount of code executed, it won’t make any difference. In terms of readability of the code I strongly suggest to use the “else” version. In this version you directly see (because of the “else”) that the first condition is not true in order to execute the else if branch. In the second example you could miss the “return” when reading and be confused why the code checks for several conditions.

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

Sidebar

Related Questions

In MySQL, is it generally faster/more efficient/scalable to return 100 rows with 3 columns,
Is it generally better practice (and why) to validate attributes in the model or
Generally, I had thought it was always better to store images in the filesystem
Generally speaking, for combining a lot of data is it better to use a
Generally speaking, the SQL queries that I write return unformatted data and I leave
Kind of a long title, but that is generally the question. I want to
I know generally it is always better performance to build mysql queries to name
The two tables below can both hold the same data - a full year,
There are some situations where there are multiple methods to calculate the same value.
I currently use Git, and am generally happy with it, but I'd like to

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.