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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T01:38:10+00:00 2026-06-08T01:38:10+00:00

How would you do this in C++? For example I’m trying to trigger a

  • 0

How would you do this in C++? For example I’m trying to trigger a program exit both if the user presses ESC or ‘q’ or ‘Q’.

I’ve tried looking for it, but I found no syntax for it in C++. I know how to do it with if-else, but is it possible with switch – case? Of course I can just make a function and call it from two separate case, but is there a way to do it just by combined case statement?

For example that’s what I’m looking for (of course not working):

void keyboard( unsigned char key, int x, int y )
{
    switch( key )
    {
        case ( 27 || 'q' || 'Q' ):
            exit( 0 );
            break;

        case 'a': ...

                case 'b': ...
    }
}
  • 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-08T01:38:11+00:00Added an answer on June 8, 2026 at 1:38 am

    Cases fall through without a break:

    case  27: //could be 27
    case 'q': //could be 27 or 'q'
    case 'Q': //could be 27, 'q', or 'Q'
        exit(0);
        break;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This example shows what I am trying to do: http://jsfiddle.net/Dqjvy/ I would like it
Trying to follow this example. (Section String sorting...) Is there anything obvious that would
I realize this example is entirely contrived, but I'm looking for a general rule
Given this example, how would I return the result of the equation rather than
I would like to see how this example of existing code would be able
i would like a simple help... i have a url like this: example.com/profile.php?id= &
Greetings How do you find the deepest node? So for this example, String would
This would be an example of database table: PHP script should limit query result
For this code example below, usually I would use [self fall]; instead of the
I found this great example of horizontal parallax http://www.perandersen.no/sandbox/parallax/ The only modification I would

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.