1/19
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai | Chat |
|---|
No analytics yet
Send a link to your students to track their progress
What is the basic syntax of a Java if statement?
if (condition) {
statements;
}
What does an else block do?
It executes when the if condition is false.
How many branches can execute in a basic if ... else statement?
One: either the if branch or the else branch.
What is the general syntax of if ... else?
if (condition) {
statements;
} else {
statements;
}
How does Java achieve the functionality of Python's elif?
Using else if.
What happens when one condition in an if / else if / else chain is true?
That branch executes and the remaining branches are skipped.
What is the purpose of the final else in an else if chain?
It executes if none of the preceding conditions are true.
What is another Java statement that implements multiway branching besides if statements?
The switch statement.
What determines which branch of a switch is executed?
The value of its controlling expression.
What is the controlling expression?
The expression enclosed in parentheses after the switch keyword.
What does each case contain?
A case label followed by a sequence of statements.
What must be true about the type of a case label?
It must be the same type as the controlling expression.
Do case labels have to cover every possible value?
No.
What does break do inside a switch?
It causes execution of the switch statement to end.
What happens if break is omitted after a case?
Execution continues into the next case.
What is this behaviour called where each case follows the next?
Fall-through
When does a switch stop executing?
When a break is executed or when the end of the switch statement is reached.
Where is default usually placed in the switch statement?
It is usually placed at the end.
When is default executed?
When none of the case labels matches the controlling expression.
What is a common use for default?
Displaying an error message when an invalid/unexpected value is supplied.