Reference.SwitchCase History

Hide minor edits - Show changes to output

August 20, 2009, at 04:48 AM by Paul Badger -
Changed line 45 from:
[[else | if ... else]]
to:
[[else | if...else]]
August 20, 2009, at 04:47 AM by Paul Badger -
Added lines 43-45:

!!!!See also:
[[else | if ... else]]
August 20, 2009, at 04:44 AM by Paul Badger -
Changed lines 3-7 from:
Like '''if''' statements, '''switch...case''' controls the flow of programs by allowing programmers to specify that different code should be executed in various conditions. In particular, a switch statement compares the value of a variable to the values specified in case statements. When a case statement is found whose value matches that of the variable, the code in that case statement is run.

The '''break''' keyword exits the switch statement. It is typically used at the end of each case. Without a break statement, the switch statement will continue executing the following expressions ("falling-through") until a break or the end of the switch statement is reached.

to:
Like '''if''' statements, '''switch...case''' controls the flow of programs by allowing programmers to specify different code that should be executed in various conditions. In particular, a switch statement compares the value of a variable to the values specified in case statements. When a case statement is found whose value matches that of the variable, the code in that case statement is run.

The '''break''' keyword exits the switch statement, and is typically used at the end of each case. Without a break statement, the switch statement will continue executing the following expressions ("falling-through") until a break, or the end of the switch statement is reached.

August 20, 2009, at 04:42 AM by Paul Badger -
Changed lines 5-6 from:
The '''break''' keyword exits the switch statement. It is typically used at the end of each case. Without a break statement, execution will continue ("fall-through") to the next case, continuing until a break statement or the end of the switch statement.
to:
The '''break''' keyword exits the switch statement. It is typically used at the end of each case. Without a break statement, the switch statement will continue executing the following expressions ("falling-through") until a break or the end of the switch statement is reached.

August 15, 2009, at 02:52 PM by David A. Mellis -
Changed line 8 from:
[@
to:
[@
Changed lines 20-21 from:
@]
to:
@]
August 15, 2009, at 02:52 PM by David A. Mellis -
Changed lines 3-11 from:
Just like '''if''' statements, '''switch / case''' statements control the flow of programs. Switch/case allows the programmer to build a list of "cases" inside a switch curly bracket. The program checks each case for a match with the test variable, and runs the code if a match is found.

'''Switch / case''' is slightly more flexible than than an '''if/else''' structure in that the programmer can determine if the '''switch''' structure should continue checking for matches in the case list, after finding a match. If the '''break''' statement is not found after running the code for a matched case, the program will continue to check for more matches among the other cases. If a '''break''' statement is encountered, case exits the structure, in the same manner as the '''if/else if''' construction.

!!! Parameters
*var - variable you wish to match with case statements
*default - if no other conditions are met, default will run
*break - without break, the switch statement will continue checking through the case statements for any other possible matches. If one is found, it will run that as well, which may not be your intent. Break tells the switch statement to stop looking for matches, and exit the switch statement.
to:
Like '''if''' statements, '''switch...case''' controls the flow of programs by allowing programmers to specify that different code should be executed in various conditions. In particular, a switch statement compares the value of a variable to the values specified in case statements. When a case statement is found whose value matches that of the variable, the code in that case statement is run.

The '''break''' keyword exits the switch statement. It is typically used at the end of each case. Without a break statement, execution will continue ("fall-through") to the next case, continuing until a break statement or the end of the switch statement.
Changed line 11 from:
//do something when var == 1
to:
//do something when var equals 1
Deleted line 12:
// break is optional
Changed line 14 from:
//do something when var == 2
to:
//do something when var equals 2
Changed lines 22-25 from:



to:
!!! Syntax

[@
switch (var) {
case label:
// statements
break;
case label:
// statements
break;
default:
// statements
}
@]

!!! Parameters

var: the variable whose value to compare to the various cases

label: a value to compare the variable to
September 07, 2008, at 01:01 AM by Paul Badger -
Changed lines 5-6 from:
'''Switch / case''' is slightly more flexible than than an '''if/else''' structure in that the programmer can determine if the structure should continue checking for matches in the case list, after finding a match. If the '''break''' statement is not found after running the code for a matched case, the program will continue to check for more matches among the other cases. If a '''break''' statement is encountered, case exits the structure, in the same manner as the '''if/else if''' construction.
to:
'''Switch / case''' is slightly more flexible than than an '''if/else''' structure in that the programmer can determine if the '''switch''' structure should continue checking for matches in the case list, after finding a match. If the '''break''' statement is not found after running the code for a matched case, the program will continue to check for more matches among the other cases. If a '''break''' statement is encountered, case exits the structure, in the same manner as the '''if/else if''' construction.
September 07, 2008, at 01:00 AM by Paul Badger -
September 07, 2008, at 01:00 AM by Paul Badger -
Changed lines 10-11 from:
*break - '''important''', without break, the switch statement will continue checking through the statement for any other possible matches. If one is found, it will run that as well, which may not be your intent. Break tells the switch statement to stop looking for matches, and exit the switch statement.
to:
*break - without break, the switch statement will continue checking through the case statements for any other possible matches. If one is found, it will run that as well, which may not be your intent. Break tells the switch statement to stop looking for matches, and exit the switch statement.
September 07, 2008, at 12:59 AM by Paul Badger -
Changed lines 5-6 from:
'''Switch / case''' is slightly more flexible than than an '''if/else''' structure in that the programmer can determine if the structure should to continue checking for matches in the case list. If the '''break''' statement is not found after running the code for a matched case, the program will continue to check for matches among the other cases. If a '''break''' statement is encountered, case exits the structure, in the same manner as the '''if/else if''' construction.
to:
'''Switch / case''' is slightly more flexible than than an '''if/else''' structure in that the programmer can determine if the structure should continue checking for matches in the case list, after finding a match. If the '''break''' statement is not found after running the code for a matched case, the program will continue to check for more matches among the other cases. If a '''break''' statement is encountered, case exits the structure, in the same manner as the '''if/else if''' construction.
September 07, 2008, at 12:57 AM by Paul Badger -
Changed lines 3-4 from:
Just like '''if''' statements, '''switch / case''' statements control the flow of programs. Switch/case allows you to make a list of "cases" inside a switch curly bracket. The program checks each case for a match with the test variable, and runs the code if if a match is found.
to:
Just like '''if''' statements, '''switch / case''' statements control the flow of programs. Switch/case allows the programmer to build a list of "cases" inside a switch curly bracket. The program checks each case for a match with the test variable, and runs the code if a match is found.

'''Switch / case''' is slightly more flexible than than an '''if/else''' structure in that the programmer can determine if the structure should to continue checking for matches in the case list. If the '''break''' statement is not found after running the code for a matched case, the program will continue to check for matches among the other cases. If a '''break''' statement is encountered, case exits the structure, in the same manner as the '''if/else if''' construction.
September 07, 2008, at 12:52 AM by Paul Badger -
Changed lines 3-4 from:
Just like If statements, switch case statements help the control and flow of the programs. Switch/case allows you to make a list of "cases" inside a switch curly bracket. The program checks each case for a match with the test variable, and runs the code if if a match is found.
to:
Just like '''if''' statements, '''switch / case''' statements control the flow of programs. Switch/case allows you to make a list of "cases" inside a switch curly bracket. The program checks each case for a match with the test variable, and runs the code if if a match is found.
September 07, 2008, at 12:51 AM by Paul Badger -
Changed lines 8-9 from:
*break - '''important''', without break, the switch statement will continue checking through the statement for any other possibile matches. If one is found, it will run that as well, which may not be your intent. Break tells the switch statement to stop looking for matches, and exit the switch statement.
to:
*break - '''important''', without break, the switch statement will continue checking through the statement for any other possible matches. If one is found, it will run that as well, which may not be your intent. Break tells the switch statement to stop looking for matches, and exit the switch statement.
July 17, 2007, at 06:18 PM by Paul Badger -
Changed lines 1-4 from:
!!Switch / Case statements

Just like If statements, switch case statements help the control and flow of the programs. Switch case's allow you to make a list of "cases" inside a switch bracket in which arduino will find the most suitable and run it.
to:
!!switch / case statements

Just like If statements, switch case statements help the control and flow of the programs. Switch/case allows you to make a list of "cases" inside a switch curly bracket. The program checks each case for a match with the test variable, and runs the code if if a match is found.
July 17, 2007, at 06:15 PM by Paul Badger -
Changed lines 1-2 from:
!!Switch Case statements
to:
!!Switch / Case statements
July 17, 2007, at 06:15 PM by Paul Badger -
Changed lines 8-9 from:
*break - '''important''', without break, the switch statement will continue checking through the statement for any other possibilities. If one is found, it will run that as well, which may not be your intent. Break tells the switch statement to stop looking for matches, and end its function.
to:
*break - '''important''', without break, the switch statement will continue checking through the statement for any other possibile matches. If one is found, it will run that as well, which may not be your intent. Break tells the switch statement to stop looking for matches, and exit the switch statement.
July 17, 2007, at 06:14 PM by Paul Badger -
Changed line 16 from:
// break is optional, without it, case statement goes on checking for matches
to:
// break is optional
July 17, 2007, at 06:13 PM by Paul Badger -
Added line 16:
// break is optional, without it, case statement goes on checking for matches
Added line 22:
// default is optional
April 16, 2007, at 05:31 PM by Paul Badger -
Changed lines 1-2 from:
!Switch Case statements
to:
!!Switch Case statements
Changed lines 25-27 from:
[[HomePage | Reference Home]]

to:


March 26, 2006, at 10:30 PM by Jeff Gray -
Changed lines 8-9 from:
*break - '''important''', without break, the switch statement will continue checking through the statement for any other possibilities. If one is found, it will run that as well, which may not be your intent.
to:
*break - '''important''', without break, the switch statement will continue checking through the statement for any other possibilities. If one is found, it will run that as well, which may not be your intent. Break tells the switch statement to stop looking for matches, and end its function.
March 26, 2006, at 10:28 PM by Jeff Gray -
Added lines 1-11:
!Switch Case statements

Just like If statements, switch case statements help the control and flow of the programs. Switch case's allow you to make a list of "cases" inside a switch bracket in which arduino will find the most suitable and run it.

!!! Parameters
*var - variable you wish to match with case statements
*default - if no other conditions are met, default will run
*break - '''important''', without break, the switch statement will continue checking through the statement for any other possibilities. If one is found, it will run that as well, which may not be your intent.

!!! Example
[@
Changed lines 21-27 from:
}
to:
}
@]


[[HomePage | Reference Home]]

March 26, 2006, at 10:22 PM by Jeff Gray -
Added lines 1-10:
switch (var) {
case 1:
//do something when var == 1
break;
case 2:
//do something when var == 2
break;
default:
// if nothing else matches, do the default
}

Share