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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T15:29:45+00:00 2026-05-30T15:29:45+00:00

I have a function which needs to execute a query based on the query

  • 0

I have a function which needs to execute a query based on the query instances inputted..
but as the conditions are increasing it is becoming tedious for me to list all of them.
For example:
suppose i have two conditions initially:

if (cond_1 == True and cond_2 == False):
    do something
elif  cond_1 == True and cond_2 == True:
    do something else
elif cond_1 == False and cond_2 == True:
    do this

….

so I guess if conditions takes on binary values then there are 2^n statements i have to write 🙁

so now i have 3 condition variables (8 statements).. and i am afraid that this number might increase in future.
Is tehre a better way to check these conditions??

  • 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-30T15:29:46+00:00Added an answer on May 30, 2026 at 3:29 pm

    Do you need to always write all all 2^n possibilities?

    And are all things you have to do different (so also 2^n actions?)

    However I can give some hints:

    Don’t use ‘== True’ or ‘== False’

    What you wrote equals:

    if cond_1 and not cond_2:
        do something 
    elif cond_1 and cond_2:
        do something else 
    elif not cond_1 and cond_2:
        do this 
    

    Also think about writing:

    if cond_1:
        if cond_2:
            Do something
        else:
            Do something 
    else:
        if cond_2:
            Do something
        else:
            Do something 
    

    You also can define functions depending on the values:

    def __init__(self):
        self.actions = {
          (False, False): action_1,
          (False, True ): action_2,
          ...
        }
    
    def action_1(self):
        some action
    
    def action_2(self):
        some action
    
    ....
    

    and call it with:

    self.actions[(cond_1, cond_2)]()
    

    If you want to optimize the number of options in case you have different conditions with similar actions, take a look to Karnaugh Maps (it is easier than it looks like):

    http://en.wikipedia.org/wiki/Karnaugh_map

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

Sidebar

Related Questions

I have an application in VC++ which needs to execute a function provided to
I have an if statement that needs to look like this: UPDATE $(input#textbox).keypress(function(e){ key==e.which;
I have an function which decodes the encoded base64 data in binary data but
I have a web service which needs to execute a command on the server
I have the following jQuery which I need adapting: $(document).ready(function(){ $(.rss-popup a).hover(function() { $(this).next(em).stop(true,
I have a function which parses one string into two strings. In C# I
I have a function which searches an STL container then returns the iterator when
I have a function which gets a key from the user and generates a
i have a function which retrieves values from a webservice , then loops through
I have a function which accepts a string parameter such as: var1=val1 var2=val2 var3='a

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.