26
Aug

Tutorial C++ #4. Switch Case. Visual Studio. FULL HD.


Very good! we move on to our next point It would be the sentence Switch Case It is basically same as the IF-ELSE statement but with the except that we can have the code a bit neater or You can see a little clearer then the switch statement is basically with Switch the word sentence and evaluates a variable in this case I placed a example Variable=2 It is an integer variable then it may be a variable-culaquiera Char, Boolean what we and if you want to evaluate a variable char, first of all everything in this example we use the word reserved switch and evaluates our variable this variable now it is going to assess the value contains the variable or value It is filed within that variable then we can put the Switch word, evaluates the variable open and close Laves and within lde that block of keys we will place the reserved word “Case” is going to evaluate values ​​we want to see in This example will evaluate the variable and the If the variable value is one 05/09/2013 this is as it as I am placing the syntax in C ++ we will place the value CASE we want to evaluate colon “:” and we can place as many line code as we want but we will always end up with a break and semicolon “;” well then the break indicates the end of the judgment of code you need run since this value is one this example one, in this example place the value is one if we want to assess what It happens when the variable has a value of two then we can put CASE 2 colon “:” put so many lines of code as we need if we end always with a break then in this case the variable is 2 that sentence or that block code goes into it is not going enter, will enter two because the variable is 2 enter Should it be 2 will print within console the value of 2 and always we ended up with a break It is as a means to break Spanish basically good and we can not specify it It is Mandatory we can specify always a default value or value defect in this case the user input 4 the variable is equal to 4 we will evaluate then the variable Variable in If you do not, if not two, will be scant 4 but there are no more cases just two in that sense it will falling into it in the case by default If default and will print “do not know” well why the values ​​is 4 and none of those values cases is specified within our block SWITCH specified opening and closing the well that would be key tuff all the you see basically switch statement Like the ileum, HE IF-ELSE we could place operators have become involved in it in in this in this early part of Video can specify the minor but more like always but always is returning a value of true or false that It is what will assess in this case by default makes operator comparison It equals one variable, 2 equals the variable? then he saves us default the comparison but we need make less and matched his most equal we can well do within at first this CASE one thing to have into account if we compare variables type CHAR or STRING variables we need to place the CASE within single quotes that’s all what we are to do well then we to see a small example quickly within our visual studio we see the IF-ELSE a basic example example of good if you need … visual studio the complete self always have to come down and give enter, he does a small example code but good serves to save us some time, in this case we did this validation or comparison is to print anything else until now the trophy Gold and silver trophy I want to do the same but with the SWITCH sentence even then we will COUT to place a way to to separate when printed inside the console, this is a little bit then we have to try to accommodate that there example SWITCH If I would also like to print that a line break remember it that skipping lines is “ENDL” a semicolon we can print so many things we want while we are separated with this symbol then we will separate Here I make a mistake because obviously this variable is not there we will separlo with the same we are comparing him example previous lives right then let’s make a comparison and switch lives will evaluate the variable that will to valuate good I want to evaluate the If this value is 3 then I can place that is equal and remember that he could place as many lines as I want and always end with a “BREAK” well and with a point semicolon “;” then in this case our It tabulate here the code looks more beautiful then in this case when the case is 3 when the value of life=3 I want to print fine gold trophy we do case when the value is 2 goes here word “BREAK” I give enter to go to the same height we will place silver trophy right then we will make a “default” for any other value can unless the trophy is bronze for any other value either with their pets. 5. well we will evaluate provided that It comes with three or 2 life as the Trophy value is what It corresponds correct then if you we want to save CONTROL + S “F5 control” we hope that he may run program and then we I want a silver trophy silver trophy example we switch to add one line break before see store “F5 CONTROL” to make it a little neater because that would be a little with disorder we go with 3 gold trophy gold trophy congratulations and the We see example makes SWITCH basically the same as making a Validation and he simply validates then what code you consider it more organized ? he has this to to print a message default in this case would be that the Finally we put ELSE to have virtually the same but we go down to print a bronze trophy “F5 control” value is neither 3 or 2, which I entered ………….10 then congratulations bronze trophy basically these two codes do what same the same, this code He didn’t come back after lunchtime either. would this code here will tell lines 9 lines of code well then I code them like you more tidier east-west here then it depends on you no problem Siwtch or IF-ELSE no no study that says consuming more processor Ifo use the siwtch as you want or as you by s more inclined to use there is no problem with this is either provided make validations Well that’s all for this video remember and share subscribe discuss any questions you may have I’ll be answering briefly the then if they want to know or receive notifications when there has been new video as simply subscribe ce they receive a notice within your device, then we We see you next video!

Tags: , , , , , , , , , , , , , , ,

2 Comments

  • Kadrath DK says:

    Buen video!
    Una pregunta… Como hago si por ejemplo yo quisiera armar una sentencia con switch case que al ingresar un valor distinto de 3, 2 o 1 me de la respuesta "error"? ejemplo con if:
    if (vidas != 3, 2, 1).
    Asi pero con switch.

  • Jimss rqz says:

    con que función de dibujan varios objetos , después de case cual es ?

Leave a Reply

Your email address will not be published. Required fields are marked *