Swift and Java control flow comparison

Source: Internet
Author: User

1. The for-in loop in Swift is very similar to foreach in Java, simplifying the traversal of the collection.

Swift syntax:

   forIndexinch 1...5{print ("The index is \ (index)")} LetBase=3Let power=3var answer=1         for_inch 1... power {Answer*=Base} print ("\ (base) to the power of \ (power) is \ (answer)")        //output "3 to the power of 59049"

The Java syntax is as follows:

      New Arraylist<string>();        Array.add ("a");        Array.add ("B");        Array.add ("C");        Array.add ("D");          for (String item:array) {            System.out.println (item);        }

Swift and Java control flow comparison

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.