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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:50:56+00:00 2026-05-25T12:50:56+00:00

I have 2 variables, width and height as integers. Any of these can be

  • 0

I have 2 variables, width and height as integers. Any of these can be positive or negative (not zero). So naturally there are 4 cases;

  1. width > 0 && height > 0
  2. width > 0 && height < 0
  3. width < 0 && height > 0
  4. width < 0 && height < 0

Now I want to take different action on each of these 4 cases without using 4 if statements.

Is there a way to aggregate these cases so that it can be put as a simple switch case

switch( aggregate ){
  case 1:
  case 2:
  case 3:
  case 4:
}

If there is no better way than using if for each then in 3D space you have 3 lengths (x,y,z) and there will be 27 if blocks.

I’m using javascript if that matters.

  • 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-25T12:50:57+00:00Added an answer on May 25, 2026 at 12:50 pm

    In javascript this is quite easy, just turn the condition upside down:

    switch(true)
    {
        case (width > 0 && height > 0):
            break;
        case (width > 0 && height < 0):
            break;
        case (width < 0 && height > 0):
            break;
        case (width < 0 && height < 0):
            break;
    
        default:
    
    }
    

    This also works in VB6/VBA but not in many other languaguages like C++ and C#.

    Here’s a simple proof: http://jsfiddle.net/avuxj/

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

Sidebar

Related Questions

I have 2 variables available about a photo i'm importing, width and height.(I could
I have 5 variables. The bitmap width and height. The screen width and height.
I have an HTML textarea that is of fixed width, but variable height. I
I have variables with values like 1.7m 1.8k and 1.2b how can I convert
I have this code: <div id=container style=width: 800px; height:300px; margin: 0 auto;overflow:hidden;></div> I need
Here's my function. The width and height variables are global integer variables defined above
I have been working with the map view and came across these variables: span.longitudeDelta
I have read in various places that having variables with global scope, i.e. a
So I have a php file that retrieves some variables with the $_GET method
I'm trying to center a heading (with variable width) and have the underline running

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.