Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the java jump statements?

2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report