swift-02 Control of Code flow

Source: Internet
Author: User

//

Main.swift

//02- Statement

//

Created by Wanghy on 15/8/9.

//Copyright (c) years Wanghy. All rights reserved.

//


Import Foundation

1.

// flow of control code using branch loops

// Branch: If If - Else Switch

// Loop: for and do - while for - inch


// true or false: with BOOL judging the true and false, the value is true and the false




//2. except Do - while and the Switch the other is basically the same, the difference is parentheses can be omitted, and curly braces cannot be omitted. For example: if (1<2){print (" I was printed ")}

If1<2

{

println ("1<2")

}

Else {

println ("1<2")

}



//3. constants can only be defined once. var-guided variables can be arbitrarily modified and assigned

var Num: Int = - ;


Num = at ;





4.

//switch You have to put all the possibilities in Case the. Multiple values can be shared one at a time, separated by commas. To have a default




//5. Looping Statements . in the 2.0 not in Do-while loops. Instead, the repeat- while loop , do in 2.0 is used as exception handling ( Do - Catch ).


// Cyclic request 1-100 and the


var sum = 0

var i = 1


while I<=

{

sum + =I+ +

}

println (sum)




//do Loops

var sum1 = 0 , j= 1


Do {

sum1 + =J+ +

} while J <=

println (SUM1)



//for Loops , operators must be separated from curly braces.


var sum3 = 0 , k= 1


for ; k <= - ; I ++ {

sum3 + +k+ +

}

println (sum3)



//for in Loops


var array = [1,2,3,4, 5]

var z:int8 = 1;

for Temp inch Array

{

if (temp! =1 && temp! = 5)

{

println (temp)

}

}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

swift-02 Control of Code flow

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.