Page 83 - iPlus_Ver_2.0_class_8
P. 83
int i;
for(i=1; i<=10; i++)
{
System.out.println("Touchpad");
}
}
}
The preceding program prints the word ‘Touchpad’ ten times.
i + JUMPING 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, jumping statements are used in Java. Java offers two jumping 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
Start
{
[statement 1]
if(< conditional expression>)
Conditional
{ True
Expression of break
[statement 2]
loop
[statement 3]
Stop
break;
False
[statement 4]
Flow chart of break statement
}
}
For example,
public class BreakStatement
{
public static void main(String args[])
{
int i;
for(i=1; i<=10; i++)
{
81
Conditional, Looping and Jumping Statements in Java

