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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T17:58:52+00:00 2026-05-12T17:58:52+00:00

Switch cases are usually like Monday: Tuesday: Wednesday: etc. I would like to use

  • 0

Switch cases are usually like

Monday: 
Tuesday: 
Wednesday: 
etc. 

I would like to use ranges.

from 1-12: 
from 13-19:
from 20-21:
from 22-30:

Is it possible? I’m using javascript/jquery by the way.

  • 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-12T17:58:52+00:00Added an answer on May 12, 2026 at 5:58 pm

    you could try abusing the switch fall through behaviour

    var x = 5;
    switch (x) {
        case  1: case 2: case 3: case 4: ...
            break;
        case 13: case 14: case 15: ...
            break;
        ...
    }
    

    which is very verbose

    or you could try this

    function checkRange(x, n, m) {
        if (x >= n && x <= m) { return x; }
        else { return !x; }
    }
    
    var x = 5;
    switch (x) {
        case checkRange(x, 1, 12):
            //do something
            break;
        case checkRange(x, 13, 19):
        ...
    }
    

    this gets you the behaviour you would like. The reason i return !x in the else of checkRange is to prevent the problem of when you pass undefined into the switch statement. if your function returns undefined (as jdk’s example does) and you pass undefined into the switch, then the first case will be executed. !x is guaranteed to not equal x under any test of equality, which is how the switch statement chooses which case to execute.

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

Sidebar

Related Questions

Is their any cases in C++ Like these case WM_COMMAND: switch(LOWORD(wParam)) That happen when
I am wondering if it is possible to create switch cases with more than
I remember from way back at university using a switch with 'binary search' or
I come from a C/Java background where switch cases have a cascading effect unless
From what I've read from various answers to similar questions, switch cases are compiled
In PHP switch statements, does placing more common cases near the top improve performance?
I have a rather long switch-case statement. Some of the cases are really short
I have a switch case like this switch($filesize_in_bytes){ case 10Mb <= $filesize_in_bytes <= 100Mb:
When trying to use a Switch Case with switch(string) for an android project ,
As of ADT 14, resource fields cannot be used as switch cases. Invoke this

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.