Java break statement can forcefully exit the current loop directly, ignoring any other statements and loop condition tests in the loop body.
The following example uses the break keyword to jump out of the current loop:
/* author by w3cschool.cc Main.java */public class Main { public static void main(String[] args) { int[] intary = { 99,12,22,34,45,67,5678,8990 }; int no = 5678; int i = 0; boolean found = false; for ( ; i < intary.length; i++) { if (intary[i] == no) { found = true; break; } } if (found) { System.out.println(no + " 元素的索引位置在: " + i); } else { System.out.println(no + " 元素不在数组总"); } }}
The output result of the above code is:
5678 元素的索引位置在: 6
The above is the Java example - the content of the break keyword usage , for more related content, please pay attention to the PHP Chinese website (www.php.cn)!