Jump Statements

In Java, jump statements transfer the control of the program from one position to another conditionally or unconditionally. Java has three jump statements: break, continue and return. The break statement skips rest of the loop and jumps over to the statement following the loop. The break statement can only be used within the body of while, do, for, or switch statement. The break statement has two separate and distinct uses that is Exiting a loop and Exiting a switch statement. The switch statement lets the programmer choose the several blocks of the code to be executed. The break statement when used in a switch takes the control outside the switch. The continue statement is used to move control to the start of the next repetition. The return statement returns the value to the calling code. The body of the method terminates as the return statement is encountered.

To Access the full content, Please Purchase

  • Q1

    How one can you tell whether a loop has executed break statement or not?

    Marks:1
    Answer:

    One can tell whether a loop has executed break statement or not by examining the loop variable.

    View Answer
  • Q2

    Write the standard library function that helps you break out of a program.

    Marks:1
    Answer:

    System.exit()

    View Answer
  • Q3

    Define jump statements.

    Marks:1
    Answer:

    These are statements that unconditionally transfer program control to another part of a program.

    View Answer
  • Q4

    Name the various jump statements used in Java.

    Marks:3
    Answer:

    A jump statement facilitates the unconditional transfer of program control.

    Java provides three jump statements:

    · return

    · break

    · continue

    return statement - returns a value from a method or a function or a constructor

    break statement - exit the current loop

    continue statement - tells the computer to skip the rest of the current iteration of the loop

    View Answer
  • Q5

    Explain the function of continue statement.

    Marks:2
    Answer:

    Continue statement forces the next iteration of the loop to take place, skipping the codes written in between. It can also take a label and returns to the next iteration of the labeled loop.

    View Answer