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)