Name and describe three types of branching mechanisms and give an example of each.
What will be an ideal response?
Three types of branching mechanisms include the if-else statement, the multi-way if-else
statement, and the switch statement. An if-else statement chooses between two alternative
statements based on the value of a Boolean expression. If you only need to perform an action if a
certain condition is true, then the else part of an if-else statement can be omitted. A multi-way if-
else statement allows several conditions to be evaluated. The first condition that evaluates to true, is
the branch that is executed. The switch statement is another multi-selection branching mechanism.
A switch evaluates a controlling expression and executes the statements in the matching case label.
```
If – else example: if ( taxableIncome > 30000)
taxRate = .135;
else
taxRate = .075;
Multi-way if-else example:
If(taxableIncome < 10000)
taxRate = .0425;
else if(taxableIncome < 30000)
taxRate = .075;
else
taxRate = .135;
Switch example: char myChar = ‘b’;
switch(myChar)
{
case ‘a’:
System.out.println(“It is an A”);
break;
case ‘b’:
System.out.println(“It is a B”);
break;
case default:
System.out.println(“Default case”);
break;
}
```
You might also like to view...
Match the following terms to their meanings:
I. Plain Text file II. Delimited file III. Imported data IV. Source file V. Linked Access table A. A file where each record displays on a separate line and the fields are separated by a delimiter B. Will not be synchronized between the imported object and the source object C. Maintains a link to the source data D. File being imported E. This format contains no formatting such as bold or italics
Why might you want to freeze rows or columns in a large dataset?
What will be an ideal response?