Source: http://www.imooc.com/code/1432
The function of continue is to skip the remaining statements in the loop body to perform the next loop.
For example, to print all the even numbers between 1--10, use the continue statement to implement the code:
Operation Result:
Task
Implementation function: Ask for all even numbers between 1 and 10.
Implementation of the idea: Define a variable sum to save the cumulative value, define a variable I save 1 to 10 integer, iterate and judge, if I cannot be divisible by 2, then end this cycle, continue to perform the next loop, otherwise accumulate sum.
Operation Result:
Please add the 9th and 10 lines in the editor on the right to the complete
1 Public classHelloWorld {2 Public Static voidMain (string[] args) {3 4 intsum = 0;//Save Cumulative value5 6 for(inti = 1; I <= 10; i++) {7 8 //If I is an odd number, end the cycle and proceed to the next cycle9 if ( ) {Ten One } A -sum = sum +i; - } the -System.out.print ("1 to 10 of all even-numbered and as:" +sum); - } -}
1 Public classHelloWorld {2 Public Static voidMain (string[] args) {3 4 intsum = 0;//Save Cumulative value5 6 for(inti = 1; I <= 10; i++) {7 8 //If I is an odd number, end the cycle and proceed to the next cycle9 if(i% 2 = = 1) {Ten Continue; One } A -sum = sum +i; - } the -System.out.print ("1 to 10 of all even-numbered and as:" +sum); - } -}
Mu class Network-android engineer first form -4-12 Java loop jump statement continue