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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:10:02+00:00 2026-05-14T02:10:02+00:00

A friend (fellow low skill level recreational python scripter) asked me to look over

  • 0

A friend (fellow low skill level recreational python scripter) asked me to look over some code. I noticed that he had 7 separate statements that basically said.

if ( a and b and c):
    do something

the statements a,b,c all tested their equality or lack of to set values. As I looked at it I found that because of the nature of the tests, I could re-write the whole logic block into 2 branches that never went more than 3 deep and rarely got past the first level (making the most rare occurrence test out first).

if a:
    if b:
        if c:
    else:
        if c:
else:
    if b:
        if c:
    else:
        if c:

To me, logically it seems like it should be faster if you are making less, simpler tests that fail faster and move on.
My real questions are

1) When I say if and else, should the if be true, does the else get completely ignored?

2) In theory would

if (a and b and c)

take as much time as the three separate if statements would?

  • 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-14T02:10:02+00:00Added an answer on May 14, 2026 at 2:10 am

    if statements will skip everything in an else bracket if it evaluates to true. It should be noted that worrying about this sort of problem, unless it’s done millions of times per program execution, is called “premature optimization” and should be avoided. If your code is clearer with three if (a and b and c) statements, they should be left in.

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

Sidebar

Related Questions

Friend of mine got asked the following question in an interview recently and im
A set of APIs that I commonly use follow a linked-list pattern: struct SomeObject
I'm heavily basing my code off of this excellent tutorial at Ars Technica, so
Friend's I need help on loading the content alone in my page without going
friend's I have a task to place the horizontal scroll or swipe menu tabs
Friend's I have a task to parse thumbnail images and to set it on
friend's, I there any possibility to bind the result of Intent class in xml
I've got a big problem but I bet it's easy to solve. I'm developing
I was searching through the web how to do time lines. I found this
example if i have follow table company one ( cid = 1 ) following

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.