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