Switch&if statements(differences)

This is a discussion on Switch&if statements(differences) within the C Programming forums, part of the General Programming Boards category; - A series of if-else if statements are less elegant for menu selection.Switch offers a better alternative. - Relational & ...

  1. #1
    Registered User
    Join Date
    Apr 2004
    Posts
    1

    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
    Neha

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

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Welcome to the real world
    Join Date
    Feb 2004
    Posts
    50
    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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21