Alert icon
We're changing our privacy policy. This stuff matters.  Learn more  Dismiss

C Programming on the Mac L27 - Switch Statement

Loading...

Sign in or sign up now!
Alert icon
Upgrade to the latest Flash Player for improved playback performance. Upgrade now or more info.
821 views
Loading...
Alert icon
Sign in or sign up now!
Alert icon

Uploaded by on Jun 18, 2010

In this tutorial I cover the switch statement which is very similar to the if statement.

  • likes, 0 dislikes

Link to this comment:

Share to:

Uploader Comments (AppleProgramming)

  • Is there any advantages of using the switch statement as opposed to the if statement, or is the switch statement pretty much obsolete compared to the if statement?

  • @Arronsyaoran I would say that for the most part, you would use if-else statements. However, if you are analyzing a very basic case, a switch may be more appropriate. Let's say you want to get the user to type a number for the month, then you could setup a switch that would check for what the number value is and printf according to what number month you enter (so 2 could be "February"). Using the switch in this case, makes it obvious what you are comparing is all of the months.

  • for the 4:44, I still don't understand why it still print key is n. I know that because there'e no "break " after the case p, so the program will continue.But it will print "key is n " only when the case'n' is satisfied. Obviously it's not....

    Please let me know .

  • @MrMacaroonable The break gets us out of the switch. Once it is in the switch it doesn't get out until it reaches the end or the break statement regardless of the actual case.

see all

All Comments (7)

Sign In or Sign Up now to post a comment!
  • @iBig13 Ya, they really have some work left to do with Xcode 4. The lack of autofill for C has really been getting on my nerves.

Loading...

Alert icon
0 / 00Unsaved Playlist Return to active list
    1. Your queue is empty. Add videos to your queue using this button:
      or sign in to load a different list.
    Loading...Loading...Saving...
    • Clear all videos from this list
    • Learn more