加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

swift -控制语句

发布时间:2020-12-14 01:55:29 所属栏目:百科 来源:网络整理
导读://// main.swift// 控制语句-03//import Foundationprintln("Hello,World!")//定义一个分数var score = 80;/*** 定义一个数组*/var scoreArr = [90,99,45,89,67,54];var minScore = 0;var maxScore = 0;var avgScore = 0.0;var sumScore = 0.0;var count = s
//
//  main.swift
//  控制语句-03
//


import Foundation

println("Hello,World!")
//定义一个分数
var score = 80;
/**
*  定义一个数组
*/
var scoreArr = [90,99,45,89,67,54];

var minScore = 0;
var maxScore = 0;
var avgScore = 0.0;
var sumScore = 0.0;
var count = scoreArr.count;

//循环所有的yuans

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("sumSocre is (sumScore) avgScore is (avgScore)");
println("maxScore is (maxScore) minScore is (minScore)");

for(var i = 0; i < count; i++){
    var s = scoreArr[i];//取得第iyuans
    println("for ...i(i) s = (s)");
    if(minScore == 0||minScore > s){
        minScore = s;
    }
    if(maxScore == 0||maxScore < s)
    {
        maxScore = s;
    }
}
avgScore = sumScore/Double(count);
println("sumSocre is (sumScore) avgScore is (avgScore)");
println("maxScore is (maxScore) minScore is (minScore)");


var index = 0;
do{
    if(index >= count){
        break;
    }
    var s = scoreArr[index];
    println("do-while s[(index)]=(s)");
}while(++index < count);


index = 0;
while(index < count)
{
    index++;
    if(index >= count){
        break;
    }
    var s = scoreArr[index];
    println("while s[(index)] = (s)");
}


//switch 之前的switch会穿透
let appType = "ios";
switch appType
{
    case "ios":
        println("ios开发");
        fallthrough;//让往下走
    case "Android":
        println("Android开发");
    case "Java":
        println("Java 开发");
default:
        println("没有任何匹配");
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读