java5
java5
execution will begin from that case onwards whose label is matching with the argument and
continues until it encounters a break statement or until the end of switch.
Iterating Statements:
For Loop: This loop can be used for executing the statements multiple times. Afor loop has to be
used when we know the exact number of iterations.
Syntax:
1 25 8... 4 7 10...
for (initialization ; condition ; increment/decrement) {
statements; 3 6 9..
Program 6:
class ForDemo {
public static void main(String[] args) {
int n =6;
for(int i=1; i<=10; i++) {
System.out.printin (n+" *"+ i+" = "+ (n*i);
Rule 1: All the three sections of the for loop are optional. If we do not specify any initialization
and if do not specify any inc/dec, then the compiler will not specify any initialization and will not
specify any inc/dec, but we do not specify any condition then the compiler will automatically
specify a boolean value true.
Rule 2: Specifying the section separators(;) in a for loopare mandatory.
for(;;) will execute for infinite times.
byte Rule 3: In the for loop, initialization section and the inc/dec section can contain any number of
valid java statements, but the condition section must contain a value of only boolean type.
Rule 4: The initialization section can contain multiple initializations separated by a comma(,) all
should be of same time and the data type should be specified only one time.
t ont Rule 5: The condition section can contain any number of
conditions, but they must be joined by
using alogical operator(& && | | | ).
Rule 6: The inc/dec section can contain
multiple increments or decrements but separated by a
ot be comma (,).
Rule 7::| If a variable is declared inside for loop,
then it can be used
i twil Rule 8: Specifying the (} is optional. If
we don't specify the only in that for loop.
statement, and that one statement is mandatory. If we (} then it will
cion
specifying the (}is mandatory. Within want to consider consider only one
the{} we can specify any multiple
statements then
number of
statements.
22