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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:14:38+00:00 2026-05-13T15:14:38+00:00

Switches seem so useless as they can be replaced with if-else statements, which can

  • 0

Switches seem so useless as they can be replaced with if-else statements, which can do much more than just match a char/int/enum etc. I can only think of one good use for a switch, and that would be for interpreting command line args.

What are some realistic uses for a switch statement?

  • 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-13T15:14:38+00:00Added an answer on May 13, 2026 at 3:14 pm

    There’s two reasons to use a switch vs if/else, in my mind:

    • The compiler may be able to optimize for the switch better.
    • The switch statement more clearly expresses the logic of the code better. Specifically, the idea that you’re taking a different branch depending on the value of something, rather than depending on more complicated logic. This is, by far, the more important reason to me.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I've been following the wrox book on begining android I just can't seem
The on/off switches shown on http://developer.android.com/design/building-blocks/switches.html#switches are awesome. I can't figure out how to
i have the following code which switches some fullscreen-background-images (fadeOut, fadeIn). setInterval(function() { var
I've got about 20 on/off switches that sends an ajax request which updates a
I am working on a ViewController which switches view based on a UISegmentControl. I
I have a function which can be run in various different ways, depending on
I can't seem to get Github integration working with my application on AppHarbor .
I can't seem to properly pin a shortcut to Juno. I've never had this
I have this problem that I can't seem to find a solution for... I
I have a problem with my coding. My code just doesn't seem to be

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.