+ 1
what is break; in java?
java
6 ответов
+ 7
Break; is used to 'break' out of a code block like loop. Essentially, it will stop executing the following code in the block and move on
For instance if you had a for loop,
for(int i = 0; i <= 5; ++i) {
if(i == 3){
break;
}
System.out.println(i);
}
This loop would only output 1 and 2 as once 3 is hit the loop is broken out of.
+ 1
When the break statement is encountered inside a loop, the loop is immediately terminated and the program control resumes at the next statement following the loop.
+ 1
break statement is used to terminate the loop..
+ 1
The break statement in Java programming language has the following two usages −
When the break statement is encountered inside a loop, the loop is immediately terminated and the program control resumes at the next statement following the loop.
It can be used to terminate a case in the switch statement (covered in the next chapter).
+ 1
terminator from a space it could be any where in block
0
break;
is a loop breaker statement in Java it also use in c, c++ and python