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 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

:bn , :bp just switches buffers I want something like ctrl-o, which has a
I seem to remember being able to print out (or locate) the specific switches
I've got about 20 on/off switches that sends an ajax request which updates a
I have a problem with my coding. My code just doesn't seem to be
I've looked around many different places, but can't seem to find a straighforward way
CPU Switches from User mode to Kernel Mode : What exactly does it do?
I'm querying a bunch of information from cisco switches using SNMP. For instance, I'm
We are looking to provide two custom Platform switches (the platform dropdown in the
I'd like to run a method when a user switches to another tab or
So I'm looking here and I see the command line switches. http://mono-project.com/Command_Line_MoMA This is

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.