Selection Control Structure Flashcards
3 types of control structures
Sequential
Decisions/selection
Iteration
Sequential structure
Statements are executed in the order in which written
Decision structure
Changes flow or execution according to a condition
If, if-else, switch
Iteration structure
Repeat execution of a set of statements
I.e for and While loops
If, if else
If(condition) {
Statements
}
If(condition) {
Statements } Else { Statements }
If - else if
If (condition1){
Statements;
} else if (condition2){
Statements;
} else if (condition 3){
Statements } else { Statements }
Nested if statements
Just meet credentials of first If to then consider second set
If (cond1) {
If (cond2) { Statements; } else {
}}
Switch statements
Enables selection from a set of options. Switchable according to a value
Switch (expression or variable) {
Case value1: statements; Break; Case value2: statements; Break; Default: statements;
}
If variable = value1 runs case, if not checks case 2 and if not then does default
What does switch work for?
Char, integral are supported, string is supported after Java 7.
FLOATS AND DOUBLES DONT WORK!
Do all conditions get run in switch?
Once a condition is met with the switch method, all ones below get used UNTIL A BREAK!
How much does a Switch run for
Once met all following cases are operated until BREAK;
Switch doesn’t work for what data type?
Floats or double