1 //: Playground-noun:a Place where people can play2 3 Import UIKit4 5 6 //1.if Statement Implementation criteria Selection7 //(1) Single branch8 varAge =99 Ten ifAge <Ten { One APrint"age less than 10 years old") - } - the //(2) Dual Branch - varOranges = - - varApples = - - + ifOranges <Apples { - +Print"more Apples") A}Else { at -Print"more oranges") - } - - - //(3) Multi-branch in varScore = $ - varGrade:character; to + ifScore >= - { -Grade ="A" the}Else ifScore >= the { * $Grade ="B"Panax Notoginseng}Else ifScore >= - { - theGrade ="C" +}Else ifScore >= - { A theGrade ="D" +}Else { -Grade ="F" $ } $ -Print"grade=\ (grade)") - the - //2. Switch statement implementation criteria SelectionWuyi /* the (1) The expression after switch can be integer type, float type, character, string, value can be a single, can also be a range - (2) Case branch does not need to add a break statement, the branch will automatically jump out of the switch after completion Wu (3) must have default, must be placed on the last side of all branches - (4) Each case must have at least one statement, and if you want to match multiple conditions, you can separate multiple conditions with commas About $ */ - varLight ="Green" - - SwitchLight { A + Case "Red": thePrint"Stop") - Case "Yellow","Green": $Print"take care to pass") the default: thePrint"the lights are broken.") the the } - in SwitchScore { the Case -... -://[90,100] theGrade ="A" About Case the.. < -://[80,90] theGrade ="B" the Case -.. < the: theGrade ="C" + Case -.. < -: -Grade ="D" the default:BayiGrade ="F" the the } - - //3.while and do While the varj =Ten; the the Repeat { the print (j) -j-- the the the} whileJ >094 the //4. For Loop the //when the operation in the loop body is independent of the loop variable, the loop variable can be replaced by _ the for_inch 0...Ten {98Print"Next") About - }101 102 //5. Control transfer Statements103 //(1) Break and Continue104 forKinch 0.. <Ten { the ifK = =3 {106 Continue;107 }108 109 print (k) the }111 the //(2) Fallthrough: Mixed processing for multiple conditions in a switch statement113Let Intergertodescribe =5 the the varDescription ="The number \ (intergertodescribe) is" the 117 SwitchIntergertodescribe {118 Case 2,3,5,7, One, -, -, +:119Description + ="a prime number, and also" - Fallthrough121 default:122Description + ="An integer"123 124 the }126 127 print (description) - 129 //(3) Tags: for complex cycle processing, labeling for process Control theLabel1: for varx =0; X <5; X + + {131 for vary =5; Y >0; y-- { the 133 ify = =x {134 BreakLabel1;135 }136 137Print"(x, y) = (\ (×), \ (y))")138 139 } $ 141 142 143 144}
Swift Process Control _03_swift Basic use