Skip to main content

Chapter 12 What is Jump|| Break|| Continue with Return Statements Explain in Details.

Intro: Hi Dear, In this post learn in details what is Jump Statements:-

Extra Important Statements 

Jump Statements: 

  • It is used to transfer the control from one point to another point in the program.

There are three Jump Statement are used in java.

  • break Statement
  • continue Statement
  • return Statement

Break Statement  

  • It is used to transfer the control out of the body of loop.
  • In another word we can say that it is terminates.
  • Break Statements are mostly used with loop(for, while, do-while) and switch statements.

Example of Break Statements:-

Example 1: Print without using break statements. 



Print 1 to 10 numbers
class Jump{
  public static void main(String arg[]){
    for(int i=1; i<=10; i++){
      System.out.print(" "+i);
    }
  }
}



Example 1.2:  Program with break Statements .


class Break{
  public static void main(String arg[]){
    for(int i=1; i<=10; i++){
      System.out.print(" "+i);
      if(i==5){   // if i=5 then break
        break;
      }
    }
  }
}



Continue Statements  

  • It is used to skip the next statements and continue the loop.
  • Continue statements are mostly used with loop(for, while, do-while).
An Example of Continue Statements:

 Example 2.1: Program with continue statements


class Continue{
  public static void main(String arg[]){
    for(int i=1; i<=10; i++){
      if(i==5)  // if i=5 then skip only 5 so next print
        continue; // using continue statements
      else
      System.out.print(" "+i);
    }
  }
}


Output:      1 2 3 4 6 7 8 9 10



Example 2.2: 


// Example 5.4: Program Continue but only print one Statement

class Continue1{
  public static void main(String arg[]){
    for(int i=1; i<=10; i++){
      if(i!=5) // Only print 5 and all skip.
        continue;
      else
      System.out.print(" "+i);
    }
  }
}


Output : 5

Example 2.3 


class Continue2{
  public static void main(String arg[]){
    for(int i=1; i<=10; i++){
      if(i<=5)  // if i<=5 print 6,7,8...
        continue;
      else
      System.out.print(" "+i);
    }
  }
}


Output: 6,7,8,9,10

Example 2.4 



class Continue3{
  public static void main(String arg[]){
    for(int i=1; i<=10; i++){
      if(i==5)   // skip 5 then next
        continue;
      else
      System.out.print(" "+i);
    }
  }
}



Output: 1 2 3 4 6 7 8 9 10
 

Return Statements  

  • return statements terminates the current function and transfer the control to the calling function.
  • we can also use return statements to transfer value one function to another.
An Example of Return statements:

Example 1: 


class Return {
  int sum(){
  int a=10, b=20;
  return a+b;
  }
  public static void main(String args[]){
    Return sc= new Return();
    int  rs= sc.sum();
  System.out.println("Addition =" + rs);
  }
}


Output:- Addition = 30



All Right guys i hope this is helpful for you, so don't forget follow me.


Comments

Popular posts from this blog

Assignment of ITA/ Information Technology and Application BCA- Technology369kk

Q1. What is  computer Explain basic computer architecture and Difference components.  2. Discuss the use of memory in computer system, Explain memory hierarchy  in details. 3. What is software? Explain difference types of software with explain. 4. Write short notes on the given:- (I) Internet. (II) LAN (Local area network ) (III) Search engine (IV) Web browser  Q 1.What is computer Explain basic computer architecture, Difference components of computer.   Computer :- Computer is defined as an electronic device that takes input data and instructions from the user and after processing them, it generates useful and desired output quickly.   A computer is designed to execute applications and provides a variety of solutions through integrated hardware and software components.                            It is fast and automatic device. It works with the help of programs and represents the d...

C++ and Java Practical All Questions Answers - BCA -Technology369kk

C++ and Java  In this post see most important questions for practical questions given by college all questions with answers . Guys I want to say that this is only for suggested post for your practical please request to you change same alphabets, words or anything  methods name and variables name because if you write all words same then this is copy paste for another peoples.  Used Topics:  Keywords, Variables, Condition Statements, Function , Array, Structure, Pointer.                           In OOPs, Class and Objects, Constructor, Poly morph, Encapsulation, Access Specifiers,                               Inheritance etc.  So, Without Time Lose Come to the Points, let's go start Now:        *************************************************************************  C++ 12 ...

Assignment of PMO (Principal of Management and Organization) - Technology369kk

 ** Assignment Of PMO ** Agenda: -  4 Questions discuss in this post. Question 1. Write a d etails note on selection why it Called. negative process.  Question 2. Write a details note on 'span of control. Question 3. Planning is an essential process, do you agree ? Discuss  Question 4. Write a note on management function. Q 1. Write a d etails note on selection why it called negative process.  Ans :-  Selection is the process of choosing the most suitable candidates out of the several candidates available.          Selection is a negative process because there may be more rejected then those selected in most of the candidates that is called selection is a negative process. → Selection process has the following steps:-  [ A .] Screening of applicants - Based on the screening of applicants only those candidates. It Called further process of selection. Who are found eligible for the job Standards of the the organization. [ B .] S...