Thread: Switch&if statements(differences)

  1. #1
    Registered User
    Join Date
    Apr 2004

    Switch&if statements(differences)

    - A series of if-else if statements are less elegant for menu selection.Switch offers a better alternative.
    - Relational & logical operators can be used in if whereas switch can only test for equality.

    Apart from these can you think of any differences between switch & if? There is a question in my text book which says "How switch is different from if statement?Illustrate through an example."

    Thanks for your time

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Um yeah... No. We're not here to do your work for you. If you're still confused, see the sig.

    Hope is the first step on the road to disappointment.

  3. #3
    Welcome to the real world
    Join Date
    Feb 2004
    I hope Quzah doesn't mind, but I'll give you a general hint. If you've learned how to write flow charts, then write out the flow chart for an if-statement and one for a switch-statement.

    Compare the two flow charts and see how each statement can be reached...

Popular pages Recent additions subscribe to a feed