Break of the Java loop jump statement
In life, we often interrupt the scheduled task for some reason. If the 10000-metre long run, only ran 500 meters due to lack of physical strength, need to quit the game. In Java, we can use the break statement to exit the specified loop and execute the code immediately after the loop.
For example, use a numeric value that loops out 1--10, where the value is greater than 2, and a multiple of 3 stops the output.
Implementation code: 650) this.width=650; "style=" width:340px; src= "Http://img.mukewang.com/536b36a80001ed4b05420273.jpg"/>
Operation Result: 650) this.width=650; "src=" http://img.mukewang.com/536b36d70001a8f200670071.jpg "/>
Code:
public class HelloWorld {
public static void Main (string[] args) {
Save Cumulative value
int sum = 0;
From 1 cycles to 10
for (int i = 1; i <=; i++) {
Accumulate sum each time you loop
sum = sum + i;
Determines whether the accumulated value is greater than 20 and exits the loop if the condition is met
if (Sum > 20) {
System.out.print ("The current cumulative value is:" + sum);
Exit loop
Break
}
}
}
}
Operation Result:
The current cumulative value is: 21
This article is from "Ghost" blog, please make sure to keep this source http://caizi.blog.51cto.com/5234706/1547771
Java Basic---Break of the Java looping jump statement (25)