How to jump out or terminate if statement in java
1. break
break: Break out of the current loop; but if it is a nested loop, you can only break out of the current layer of loops, and only break layer by layer can Break out of all loops.
for (int i = 0; i < 10; i++) { if (i == 6) { break; // 在执行i==6时强制终止循环,i==6不会被执行 } System.out.println(i); } 输出结果为0 1 2 3 4 5 ;6以后的都不会输出
2. continue
continue: Terminate the current loop, but do not jump out of the loop (the statements after continue in the loop will not be executed), and continue to execute the loop according to the loop conditions.
for (int i = 0; i < 10; i++) { if (i == 6) { continue; // i==6不会被执行,而是被中断了 } System.out.println(i); } 输出结果为0 1 2 3 4 5 7 8 9;只有6没有输出
3. return
(1)return Exits from the current method, returns to the statement of the called method, and continues execution.
(2)return Returns a value to the statement that calls the method. The data type of the return value must be consistent with the type of the return value in the method declaration.
(3) Return can also be followed by no parameters. Without parameters, it returns empty. In fact, the main purpose is to interrupt the execution of the function and return to the calling function.
Special note: Methods with a return value of void must use return to jump out from a certain judgment.
Recommended tutorial: java quick start
The above is the detailed content of How to jump out or terminate if statement in java. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function