Swift Loop Statements

Source: Internet
Author: User

// loop statements

for var i = 0 ; i < 5 ; i++ {

Print("i = \(i)")

}

var j = 0

for j = 0; j <

Print("j = \(J)")

}

// for the first use of

//1. Traversing strings

let str = "Qwertyu"

for temp in str.characters {

Print("temp = \(temp)")

}

for Temp1 in 1... 6 {

Print("temp1 = \(temp1)")

}

//While statement

/*

format

While Boolean { }

description :

The while statement is stopped only if the Boolean value after the while is false, or the while statement is always executed

*/

var x = 0

while (x < 3)

{

Print("x = \(x)")

X + +

}

//Repeat while

/*

format:

Repeat {} while Boolean value

Description:

1: Execute Repeat statement now

2: Then execute while statement

3: Stop the repeat while statement if the Boolean value after the while statement is false , or the repeat while statement is executed all the time

*/

var y = 0

repeat {

y = y + 1

Print("y = \(y)")

}while (Y < 5)

Swift Loop Statements

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.