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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:07:01+00:00 2026-06-01T02:07:01+00:00

The GNU case range extension allows case ranges in switch statements: switch (value) {

  • 0

The GNU case range extension allows case ranges in switch statements:

switch (value) {
    case 1 ... 8:
        printf("Hello, 1 to 8\n");
        break;
    default:
        printf("Hello, default\n");
        break;
}

How would you convert this to standard C (c99, or c89)? Add the individual case statements?

Edit: How would you handle very large switch statements specifically?

  • 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-06-01T02:07:02+00:00Added an answer on June 1, 2026 at 2:07 am
    switch(value) 
    {
        case 1:
        case 2:
        case 3:
        case 4:
        case 5:
        case 6:
        case 7:
        case 8:
            printf("Hello, 1 to 8\n"); 
            break;     
        default:         
            printf("Hello, default\n");         
            break; 
    } 
    

    EDIT: To answer the comment.
    If you have too many cases, then You might want to consider replacing the switch-case with if-else constructs. It can be much cleaner, concise & readable.

    if (value >=1 && value <= 8) 
    {    
        printf("Hello, 1 to 8\n"); 
    } 
    else 
    {   
        printf("Hello, default\n"); 
    }  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What GNU/Linux command-line tool would I use for performing a search and replace on
In GNU Make, currently I am lowering the case of a drive letter using
Because GNU make allows variables to be as large as memory allows, it has
is there any nice GNU way how to measure average (worst case, best case)
GNU sed version 4.1.5 seems to fail with International chars. Here is my input
GNU gcc 4.3 partially supports the upcoming c++0x standard: among the implemented features the
GNU Emacs 23.1 I am using iswitchb. However, when I press C-x b I
Gnu Emacs is insisting on indenting my typedef as follows: typedef enum { horizontal,
The GNU Scientific library has a multi-dimensional function minimization framework. However, its caveats explicitly
The GNU/Linux version of cp has a nice --update flag: -u, --update copy only

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.