Java Reference
In-Depth Information
return response;
}
public static void main(String [] args) {
System.out.println(convertGrade('C'));
}
}
The value being switched on is the parameter grade . Because each case statement uses a
final variable, the code compiles fi ne and the output is
Not bad.
The for Statement
The exam objectives state that you should be able to “develop code that implements all
forms of loops and iterators, including the use of for and the enhanced for loop (for-each),
and explain the values taken by loop counter variables during and after loop execution.”
This section discusses these details of for and for-each loops. A for statement is a
repetition control structure that is useful for repeating a block of code a fi xed number of
times. There are two types of for statements in Java:
The basic for statement
The enhanced for statement
This section discusses the details of both types of for statements, starting with the basic
for statement.
The Basic for Statement
A basic for statement has the following properties:
The two semicolons are required and create three sections: an initialization
statement, a boolean expression, and an update statement.
The initialization step occurs once at the beginning of the loop.
The boolean_expression must evaluate to true or false .
The initialization and update_statement sections can contain multiple statements,
separated by commas.
Search WWH ::




Custom Search