You have already seen if, which allows you to make a decision whether to execute a block of code based upon the result of its expression. Sometimes a decision in C++ can be made better in other ways. This video demonstrates using switch.
- [Instructor] Making decisions with switch.…Previously, we looked at arrays.…In this video, we're going to take a look…at how to use switch.…We have already seen if, which allows us to make a decision…whether to execute a block of code…based upon the result of its expression.…Sometimes, a decision in C++ can be…better made in other ways.…When we have to make a decision based on a clear list…of possible outcomes, which doesn't involve…complex combinations or wide ranges of values,…then switch is usually the way to go.…
We start a switch decision as seen in this code.…In this example, expression could be an actual expression,…or just a variable.…Then, within the curly braces, we can make decisions…based on the result of the expression,…or the value of the variable.…We do this with the case and break keywords.…You can see it in that each case states a possible result,…and each break denotes the end of the case,…and the point at which execution leaves the switch block.…We can also optionally use the default keyword…
This course was created and produced by Packt Publishing. We are honored to host this training in our library.
- Creating the main game loop
- Drawing the game background
- Handling errors
- Manipulating C++ variables
- Randomizing numbers
- Making decisions with if, else, and switch
- Moving game objects
- Pausing and restarting games
- Adding scoring and messages
- Using class enumerations and arrays
- Adding sound effects
- Object-oriented programming in C++
- C++ references
- Texture management
- Collision detection
- Implementing the HUD
- Finishing the game
Skill Level Beginner
1. C++, SFML, Visual Studio, and Starting the First Game
2. Variables, Operators, and Decisions
3. C++ Strings, SFML Time, Player Input, and HUD
4. Loops, Arrays, Switch, Enumerations, and Functions
5. Collisions, Sound, and End Conditions
6. Object-Oriented Programming, Classes, and SFML Views
7. C ++ References, Sprite Sheets, and Vertex Arrays
8. Pointers, the Standard Template Library, and Texture Management
9. Collision Detection, Pickups, and Bullets
10. Layering Views and Implementing the HUD
Updating the HUD each frame3m 24s
11. Sound Effects, File I/O, and Finishing the Game
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.