Get the App
SLTechnology News&Howtos  ›  Development  › 

What are the java jump statements?

Shulou Source: shulou.com Published: 2022-06-02 03:12:29 09月29日 Update

This article will explain in detail what are the java jump statements, the quality of the article content is high, so Xiaobian shares it for everyone to make a reference, I hope you have a certain understanding of relevant knowledge after reading this article.

Java supports three jump statements: break, continue and return. These statements transfer control to other parts of the program.

Each is discussed below.

Note: In addition to the jump statements discussed here, Java supports another way to change the flow of your program execution: through exception handling. Exception handling provides a structured way for your program to catch and handle run-time errors. It is controlled by five keywords: try, catch, throw, throws, and finally. Essentially, exception handling allows your program to make a nonlocal branch jump. Because exception handling is a big topic, we'll devote chapter 10 to it.

5.3.1 Using the break statement

In Java, break statements have three roles. First, you've seen that in switch statements, it's used to terminate a sequence of statements. Second, it can be used to exit a loop. Third, it can be used as an "advanced" goto statement. The last two uses are explained below.

Use break to exit the loop

You can use the break statement to force a loop out directly, ignoring any other statements in the loop body and the loop's conditional tests. When a break statement is encountered in the loop, the loop is terminated and program control resumes with the statement following the loop. Here is a simple example:

// Using break to exit a loop.

class BreakLoop {

public static void main(String args[]) {

for(int i=0; i

Tags: Statements loops programs tags controls codes methods outputs forms facets runs processes compiles examples conditions structures compilers jackers loop bodies situations Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi vpn Apple Shulou Tech Info Shulou Information