Swift Study Notes 05

Source: Internet
Author: User

1. Swift does not need to write break, so this kind of fallthrough will not happen. 2. // The variable name is not used and can be replaced "_".
 
For _ in 1... power {answer * = base}

3. Case can match more types, including range matching, tuple, and specific types.
Use Case
 
Case 1... 3: naturalcount = "a few"

4. If there are multiple matches, only the first matched case Branch will be executed, and the remaining matching case branches will be ignored.

5. Bind case values. In this example, default is not required.
Let anotherpoint = (2, 0) Switch anotherpoint {Case (Let X, 0): println ("on the X-axis with an X value of \ (x )") case (0, let y): println ("on the y-axis with a Y value of \ (y)") case Let (X, Y ): println ("somewhere else at (\ (x), \ (y)")} // output "on the X-axis with an X value of 2"

6. // if and only if the where statement is true, the matched case Branch will be executed.
 
Let yetanotherpoint = (1,-1) Switch yetanotherpoint {case Let (X, Y) where x = Y: println ("(\ (x), \ (y )) is On The Line X = y ") case Let (X, Y) where x =-y: println (" (\ (x), \ (y )) is On The Line X =-y ") case Let (X, Y): println (" (\ (x), \ (y )) is just some arbitrary point ")} // output" (1,-1) is on the line x =-y"

July 03, 2014



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.