JUMP STATEMENT IN LOOP PROGRAM – Return

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

class LoopEx4

{

            void method1()

            {

                        int x;

                        for(x=1;x<=10;x++)          // Loop

                        {

                                    if(x==5)                     // return from method1()

                                    return;

                                    System.out.println(“X = ” + x);

}

System.out.println(“Bye from Method”);

}

}

class loop4

{

          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”);

}

}

Output:

X = 1

X = 2

X = 3

X = 4

Bye from Main

 

About Program

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.

NoTitle
1Work 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.

Share and Enjoy

  • Facebook
  • Twitter
  • Delicious
  • LinkedIn
  • StumbleUpon
  • Add to favorites
  • Email
  • RSS

925total visits,1visits today


mayank

Hello, I am Maddy a Java blogger, trainer and developer

Related articles

1 Comment

  1. December 10, 2016 - 8:50 pm

    My brother recommended I might like thi website. He was entirely right.

    This post truly made my day. You cann’t imagine just how much time I hhad
    spent for this information! Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *

Your comments (*)

Name (*)

Your full name please.

Email address (*)

Used for gravatar.

Website

Link back if you want.

Enter Captcha Here :*

Reload Image

EmailEmail
PrintPrint