Created
February 6, 2023 20:15
-
-
Save foxicode/4816fd0fb8f43df3e3536396d803e1e0 to your computer and use it in GitHub Desktop.
Switch - case - where construction
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let point1 = (1.5, 0.5) | |
| let point2 = (1.0, 0.0) | |
| let point3 = (0.5, 0.5) | |
| for point in [point1, point2, point3] { | |
| switch point { | |
| case let (x, y) where pow(x, 2) + pow(y, 2) < 1.0: | |
| print("Point \(x), \(y) is inside the circle") | |
| case let (x, y) where pow(x, 2) + pow(y, 2) == 1.0: | |
| print("Point \(x), \(y) is on the circle border") | |
| case let (x, y): | |
| print("Point \(x), \(y) is outside the circle") | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment