swift -控制語句

來源:互聯網
上載者:User

標籤:控制語句   swift   ios開發   

////  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 = scoreArr.count;//迴圈所有的yuansfor 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("沒有任何匹配");}

著作權聲明:本文為博主原創文章,未經博主允許不得轉載。

swift -控制語句

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.