var score = 101var letterGrade = ""switch score{ case >100: letterGrade = "A+ With Extra Credit"case 90...100: letterGrade = "A"case 80...89: letterGrade = "B"case 70...79: letterGrade = "C"case 60...69: letterGrade = "D"default: letterGrade = "Incomplete"}解决方法 是一个简单的解决方案,将它绑定到这样的常量:
var score = 101var letterGrade = ""switch score{case let x where x > 100: letterGrade = "A+ With Extra Credit"case 90...100: letterGrade = "A"case 80...89: letterGrade = "B"case 70...79: letterGrade = "C"case 60...69: letterGrade = "D"default: letterGrade = "Incomplete"}
这完全符合您的需要
总结以上是内存溢出为你收集整理的Swift:在Switch语句中使用比较运算符全部内容,希望文章能够帮你解决Swift:在Switch语句中使用比较运算符所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)