Swift Learning -- use if and switch for conditional operations, and use for, while, and do-while for Loop
// Switch supports any type of data and various comparison operations-not only integers and test equality
// If the default program is removed, an error is returned.
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)")
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 = 3
while n <100 {
n = n * 2
}
println ("n is \ (n)")
// do-while loop
var m = 3
do {
m = m * 2
} while m <100
println ("m is \ (m)")
Print results
Stringscomment is say hello2 and hello3
N is 192
M is 192