Swift控制语句

Swift控制语句,第1张

概述import Foundation println("Hello, World!") //定义一个分数 var score = 80; //定义一个数组 var scoreArr = [90,100,23,43,43,67]; var minScore = 0; //最小 var maxScore = 0; //最大 var avgScore = 0.0 //平均 var sumScore = 0 import Foundation println("Hello,World!") //定义一个分数 var score = 80; //定义一个数组 var scoreArr = [90,100,23,43,67]; var minscore = 0; //最小 var maxscore = 0; //最大 var avgscore = 0.0 //平均 var sumscore = 0.0 //分数总和 double类型 var count = scoreArr.count; //循环数组所有元素 for s in scoreArr { sumscore = sumscore + Double(s); println("s is \(s)"); if (minscore == 0||minscore > s ) { minscore = s; } if (maxscore == 0||maxscore > s ) { maxscore = s; } } avgscore = sumscore / Double(count); println("sumscore is \(sumscore) avgscore = \(avgscore)"); println("max score is \(maxscore) min score =\(minscore)") for (var i = 0;i < count;i++) { var s = scoreArr[i]; println("for ..i\(i) s=\(s)"); if (minscore == 0 || minscore > s) { // ==0 就不对,swift对空格要求很严 minscore = s; } if (maxscore == 0 || maxscore < s) { maxscore = s; } } avgscore = sumscore / Double(count); println("for .sumscore is \(sumscore) avgscore = \(avgscore)"); println("for max score is \(maxscore) minscore = \(minscore)"); var index = 0; do { if (index >= count) { //> = 就不对 break; } var s = scoreArr[index];//取得第i个元素 println("do-while s[\(index)] = \(s)"); } while(++index < count) while(index < count) { var s = scoreArr[index]; println("while s[\(index++)] = \(s)"); } //switch let appType = "ios"; switch appType { case "ios": println("ios"); fallthrough; //往下走一步 case "androID": println("wp") default: println("wu"); } 总结

以上是内存溢出为你收集整理的Swift控制语句全部内容,希望文章能够帮你解决Swift控制语句所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1091488.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-27
下一篇 2022-05-27

发表评论

登录后才能评论

评论列表(0条)

保存