Jump Statement is Loop Program – Return?
This is best work of return statement in java program.
Using of this statement we can manage the loop and method program.
I give one example on it.
Our loop is from 1 to 1000.
But we have to stop loop at 200 number and back to main program.
That time return statement will help us.
Program on – Jump Statement – Return
for(x=1;x<=10;x++) // Loop
if(x==5) // return from method1()
System.out.println(“X = ” + x);
System.out.println(“Bye from Method”);
public static void main(String args)
// Create an object of class LoopEx4
LoopEx4 obj = new LoopEx4();
obj.method1(); // call to method1()
System.out.println(“Bye from Main”);
X = 1
X = 2
X = 3
X = 4
Bye from Main
In this program, Loop is working till 4 numbers.
At 5 number, loop and method both breaks because of if condition
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.
1200total visits,6visits today