java break
javaIn Java, the break
statement is used to exit a loop or switch statement early, before the loop or switch statement is
completed. It terminates the current loop or switch statement and transfers control to the next statement after the loop
or switch.
Here is an example of how to use the break
statement in a loop in Java:
public class Main {
public static void main(String[] args) {
// Define a loop that counts from 1 to 10
for (int i = 1; i <= 10; i++) {
// Print the current count
System.out.println(i);
// If the count is 5, exit the loop
if (i == 5) {
break;
}
}
}
}
This code defines a loop that counts from 1 to 10 and prints the current count to the console. If the count is 5, the
break
statement is executed and the loop is terminated.
The break
statement can also be used to exit a labeled loop, by specifying the label of the loop before the break
statement.
For more information on the break
statement and how to use it in Java, you can refer to the Java documentation:
break
statement: https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/break.html- Loops: https://docs.oracle.com/en/java/javase/11/language/loop.html
Other Article on Tag java
- - after and before in java date
- - am pm java date format
- - apk minecraft java edition
- - as been blocked by CORS policy Response to preflight request doesn't pass access control check It does not have HTTP ok status
- - bubble sort in java
- - Can I compile and run a spring boot jar from inside another spring boot application
- - convert java date to localdate
- - design patterns in java
- - encrypt by java and decrypt by node
- - exception handling in java