Jump Statement is Loop Program – Break?
This is best work of break statement in java program.
Using of this statement we can control the loop program.
I give one example on it.
Our loop is from 1 to 1000.
But we have to stop loop in 100 Number.
That time break statement will help us.
Introduce Simple Class Example in this blog. But do not take seriously class example just focus on jump statement.
Program on – Jump Statement – Break
for(x=1;x<=10;x++) // Loop
if(x==5) // Break the loop
System.out.println(“X = ” + x);
System.out.println(“Bye from Method”);
public static void main(String args)
// Create an object of class LoopEx2
LoopEx2 obj = new LoopEx2();
obj.method1(); // call to method1()
System.out.println(“Bye from Main”);
X = 1
X = 2
X = 3
X = 4
Bye from Method
Bye from Main
In this program, Loop is working till 4 numbers.
At 5 number, loop breaks because of if condition.
Then program print “Bye from Method” statement
Then program reach at main program and then print “Bye from Main”
You can see this program on YouTube
List of Jump Statement Tutorial.
|1||Work on same example. [Using Command Line Argument]|
If you have problem on this blog, you can directly comment on it. This tutorial will help you understand the concepts of java loop programs.
894total visits,6visits today