Page 86 - TP_iPlus_V2.1_Class8
P. 86
System.out.println("Touchpad");
}
}
}
The preceding program prints the word ‘Touchpad’ ten times.
Quick Byte
The for-each loop in Java is a simpler way to iterate over
elements of an array or a collection, like an ArrayList. It is also
known as an enhanced for loop. The syntax of for-each loop is
as follows:
for (dataType item : collection)
{
// body of loop
}
i + JUMP STATEMENTS
Sometimes, there is a situation when the control of program needs to be transferred out of
the loop body, even if all the values of the iterations of the loop have not been completed. For
this purpose, jump statements are used in Java. Java offers two jump statements — break and
continue — which are used within the loops.
The break statement
The break statement forcefully terminates the loop or switch execution within which it lies. It
skips the rest of the statements next to the break keyword in the loop and jumps over to the
statement following the loop.
The syntax of the break statement is as follows:
Loop
{
[statement 1]
if(< conditional expression>)
{
[statement 2]
[statement 3]
break;
[statement 4]
}
}
84
iPlus (Ver. 2.1)-VIII

