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

  • Home
  • SEARCH
  • 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 4024442
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:43:20+00:00 2026-05-20T10:43:20+00:00

Does this condition: if (x > 1) //some logic else if (y >47) //some

  • 0

Does this condition:

if (x > 1)
//some logic
else if (y >47)
//some logic
else
//default logic

Does this always translate to :

if (x >1)
{some logic}
else{
  if (y >47)
    {some logic}
    else
    {default logic}
}

Or are there exceptions? If no exceptions, then is there a best practice of how to write this?

  • 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-20T10:43:20+00:00Added an answer on May 20, 2026 at 10:43 am

    These forms are logically equivalent, yes. I think the best practise is to write the code so it is as easy to understand as possible.

    Consider:

    if (A) { // code #1 }
    else if (B) { // code #2 }
    else { // code #3 }
    

    The truth table is then

    A B code
    T T #1    *
    T F #1    *
    F T #2
    F F #3
    

    Which is the same as for

    if (A) { // code #1 }
    else {
        if (B) { // code #2 }
        else { // code #3 }
    }
    

    * NB: Most languages will short-circuit these cases and not evaluate B at all, but some do. This doesn’t affect the logic though.

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

Sidebar

Related Questions

How does this condition work? I'm unable to comprehend this. if ([newLocation.timestamp timeIntervalSince1970] <
I have code that all over the place(probably 20-30 instances) does this: <widget>.setVisible((condition ==
Does this code always evaluate to false? Both variables are two's complement signed ints.
Does this work well as a Singleton in actionscript? i.e. are there any gotchas
I have a constructor in a class that does some kind of logic: public
I'm working with some code that does this: var _init = false; this.init =
So, I'm attempting to have a method that effectively does this: - (void)doWhile: (/*some
Does this function has the same behavior that memset ? inline void SetZeroArray( void
Does this mean I can't update another table from a trigger if I'm using
Does this look like it should work? I'm wanting to generate directions from one

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.