Goto statements in Java

Source: Internet
Author: User

  
 
  1. List<Integer> nums = new ArrayList<Integer>();
  2. //计算从2开始,到upper的所有质数
  3. outer:
  4. for(int i=2;i<=upper;i++)
  5. {
  6. //用i除以从2开始、到i的平方根的所有数
  7. for(int j=2;i<Math.sqrt(i);j++)
  8. {
  9. //如果可以整除,则说明这个数不是质数
  10. if(i!=2 && i%j ==0)
  11. {
  12. continue outer;
  13. }
  14. }
  15. nums.add(i);
  16. }
The above program is used to find all the prime numbers from 2 to upper and add them to the ArrayList. Outer: "is a label name of its own definition, through break or continue to jump to this position, is generally used to jump out of the loop." This syntax is similar to goto in the C language.


From for notes (Wiz)

Goto statements in Java

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.