Mu Class Network-android engineer first form the continue of -4-12 Java loop jump statement

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.