: Playground-noun:a place where people can playimport uikit//determine the interval var score = 90switch Score {case 0:print ("Yo U got an egg! ") Case 1..<60:print ("Sorry, you failed.") Case 60..<70:print ("Just passed.") Case 70..<80:print ("no bad.") Case 80..<90:print ("Good job!") Case 90..<100:print ("great!") Case 100:print ("prefect!") Default:print ("Something wrong with your score")}//to determine the tuple (1) var coordinate = (1, 1) switch coordinate {case (0, 0): Print ("It ' s at origin!") Case (1, 0): Print ("It's a unit vector on the positive x-axis.") Case ( -1, 0): Print ("It's a unit vector on the negative x-axis.") Case (0, 1): Print ("It's a unit vector on the positive y-axis.") Case (0,-1): Print ("It's a unit vector on the negative y-axis.") Default:print ("It's just an ordinary coordinate")}//to determine the tuple (2)//You can pass the tuple's "_" to ignore a value in the tuple var Coordinate2 = (0, 1) switc H Coordinate2 {case (0, 0): Print ("It's at origin!") Case (_, 0): print (\ (\ (coordinate2.0), 0) is on the x-axis. ") Case (0, _): Print ("(0, \ (coordinate2.1)) are on the y-axis.") Case ( -2...2, 0...2): print ("The coordinate is (\ (coordinate2.0), \ (coordinate2.1))") Default:print (\ (\ (Coordinate2. 0), \ (coordinate2.1)) is just an ordinary coordinate ")}//to determine the tuple (3)//value Bindingvar Coordinate3 = (0, 1) switch Coordin ate3 {case (0, 0): Print ("It's at origin!") Case (Let x, 0): Print ("(\ (coordinate3.0), 0) was on the x-axis.") Print ("The X value is \ (x)") case (0, let y): print ("(0, \ (coordinate3.1)) is on the y-axis.") Print ("The Y value is \ (y)"): Print ("The coordinate is (\ (x), \ (y))")}//the tuple (4)//where//implementation in the selected Simultaneous logical operation var coordinate4 = (3, 3) switch Coordinate4 {case let (x, y) where x = = Y:print ("(\ (x), \ (y)), x = = y") (x, y) where x = =-y:print ("(\ (x), \ (y), x = =-Y") Case-let (x, y): Print ("(\ (x), \ (y))")}//to the tuple (5) var Coursei NFO = ("3-2", "interval operator") switch Courseinfo {case (_, let Coursename) where CoursenaMe.hassuffix ("operator"): Print ("Course <\ (Coursename) > is a course for introducing operators") Default:print ("<\ (courseinfo.1) > is other course")}// where (6) var courseName2 = "How to get along with a jerk" switch courseName2 {case-let str where str.hassuffix ("operator"): Print ("Course <\ (Coursena ME2) > is the course "to introduce the operator") Default:print ("<\ (courseName2) > is other course")}//to determine the tuple (7) var Coordinate7 = (1, 0) switch Coordina Te7 {case (0, 0): Print ("It's at origin!") Fallthrough//Fallthrough will continue the next casecase after the current case has been executed (_, 0): Print ("(\ (coordinate7.0), 0) is on the x-axis.") Fallthroughcase (0, _): Print ("(0, \ (coordinate7.1)) is on the y-axis.") Fallthroughcase ( -2...2, 0...2): print ("The coordinate is (\ (coordinate7.0), \ (coordinate7.1))") Default:print (\ (\ (c oordinate7.0), \ (coordinate7.1)) is just an ordinary coordinate ")}
Advanced usage of Swift-24-switch statements