Skip to content

Instantly share code, notes, and snippets.

@foxicode
Created February 6, 2023 20:15
Show Gist options
  • Select an option

  • Save foxicode/4816fd0fb8f43df3e3536396d803e1e0 to your computer and use it in GitHub Desktop.

Select an option

Save foxicode/4816fd0fb8f43df3e3536396d803e1e0 to your computer and use it in GitHub Desktop.
Switch - case - where construction
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