Example to use
if
and switch
to make conditionals, and use for
-in
, for
, while
, and do
-while
to make loops
let scores = [50 , 70, 80, 40,54, 44, 88]
var count = 0
for score in scores {
if score < 50 {
++count
}
}
print("You failed in \(count) subject")
Switch case:
Switch case:
let constand = "am swift"
switch constand {
case "objective c" :
let result = "Am objecive C"
case let x where x.hasSuffix("swift"):
let result = "ss\(x)ss"
default :
let result = "Am not in this family."
}
No comments:
Post a Comment