In addition to having all C control flow structures, Swift also has the for...in in OC ... The structure facilitates traversal of arrays, dictionaries, and so on.
Cycle
The swift cycle provides four structures:
<1>for...in: Commonly used to iterate over arrays, similar to Forearch in C #
var myArray = ["string1",123,456]
for i in myArray{
println("item is \(i)")
}
var myArray = ["v1":"string1","v2":123,"v2":11.34]
for (name,value) in myArray{
println("key name=\(name) key value=\(value)")
}
<2>for...condition...increment: This structure is the same as OC's for.
for var i=0; i<10; i++{
println("index is \(i)")
}
<3>while: As with OC's while
while 1<2 {
println("this is while loop")
}
<4>do...while: Same as OC's Do...while
do{
println("this is do while")
}while 1<2
"Conditional Statement"
<1>if...else
if 1<2 {
.......
}
else if 1<3{
.......
}
else{
.......
}
<2>switch
var num:int
switch num {
case 1:
case 2:
println("num is 2")
case 3:
println("num is 3")
case 4,5,6:
println("num is 4 or 5 or 6")
default:
println("num is not 1 or 2 or 3")
}
In layman Swift (2)--Control flow