top of page

Programming structures 'switch, case, break'

This structure allows you to do the same as would many " if ... else if ... else " followed the conditions will always use the comparator " == ". The "structure switch " analyzes a variable by value performs some action. this structure is made ​​up of different cases ( case ) running on the value of the " Variable " we selected, each case must end with an instruction " break;". which tells the program that there ends If any case is met is execute block " default ". the block structure " switch " is found in the section of "logic " and use it must arrastarlo the work area and click the gear to add the " cases " that necessary and a block of " default ":

Once you add the variable that will select the case and the numbers of cases, the structure " switch " would be as follows:

Example 1:

In this example the blue LEDs will light up if button 1is pressed, green if button 2 is pressed and if none if no buttons are pressed.

When pressed a button that is stored in the variable " button " and then enters the "structure switch " and depending on the value of the variable case one is done, if we press button 1 case 1 is made, if we press button 2 , case 2 is performed, and if we press any button or none it finds no case structure, the case "is made â€‹â€‹default ".

bottom of page