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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T08:14:55+00:00 2026-05-30T08:14:55+00:00

if((x == 5) || (x == 2)) { [huge block of code that happens]

  • 0
if((x == 5) || (x == 2)) {  
    [huge block of code that happens]  
    if(x == 5)  
        five();  
    if(x == 2)  
        two();  
}

So I’m checking for either 5 or 2. And there is a huge block of code that happens after either 5 or 2. The problem is that then I want to do different things depending on whether it is 5 or 2. I didn’t want to have separate conditionals for 5 or 2 for the huge block of code (duplicating it would be unwieldy). I also didn’t like the way I did it above because x is actually really long.

Is there a way to say something like:

if((x == 5) || (x == 2)) {  
    [huge block of code that happens]  
    if(first conditional was true)  
        five();  
    if(second conditional was true)  
        two();  
}  

I can always do it the way I did above. Just curious if such an option exists.

  • 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-30T08:14:56+00:00Added an answer on May 30, 2026 at 8:14 am

    One way I can think of is basically to “alias” the longer boolean expressions in the if condition:

    boolean expr1, expr2;
    
    if (expr1 = (x == 5) | expr2 = (x == 2)) {  
        // huge block of code that happens
        if (expr1) five();
        if (expr2) two();
    }
    

    I used non short-circuiting operator to ensure expr2 gets assigned.

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

Sidebar

Related Questions

I have a block of code that's essentially: for(int i=0;i<aInt;i++){ CGPoint points[2] = {CGPointMake(i,0),CGPointMake(i,bArray[i])};
I have a huge web app that is having issues with memory leak in
I have some code that roughly does this inside of a GAE worker task:
Is this good practice? Or should I just replace the code block between {
I'm new to JQuery and don't have a huge background in Javascript, either -
Hi everyone I've got a huge issue that I don't quite understand why it's
I have started working on a huge PHP application that has thousands of lines
I just saw this block of code on the Wikipedia article on conditional operators:
So that IO doesn't block the UI thread in my Android app, I'm trying
I need to prepend a huge DIV block, which can be seen at the

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.