Swift Learning-use if and switch to perform conditional operations, use For,while, and Do-while to cycle (iii)

Source: Internet
Author: User

Swift Learning-use if and switch for conditional operation, use For,while, and do-while to cycle


//switch supports arbitrary types of data and a variety of operations- - not only integers, but also test equivalence

// Note that if you remove the default program, you will get an error

Let strings = ' hello3 ' switch strings{case    ' hello1 ': let    stringscomment = ' say Hello1 '    println (" Stringscomment is \ (stringscomment) ") Break case    " Hello2 "," Hello3 ": let    stringscomment =" Say Hello2 and Hello3 "    println (" Stringscomment is \ (stringscomment) ") The break case let    x where X.hassuffix (" Hello4 "): Let    stringscomment = "is it a spicy \ (x)?"

" println (" Stringscomment is \ (stringscomment) ") break default: let stringscomment =" Say Everything " println (" Stringscomment is \ (stringscomment) ")}



Simple while and do-while loops


While loop var n = 3while N < 100{    n = n*2}println ("N is \ (n)")//do-while cyclic var m = 3do{    m = m*2}while m < 1 00println ("M is \ (m)")

Print results

Stringscomment is say Hello2 and Hello3

N is 192

M is 192



Swift Learning-use if and switch to perform conditional operations, use For,while, and Do-while to cycle (iii)

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.