allows you to use statements such as for-in
, while
, switch
& if/else
to iterate over sequences or execute different pieces of code based on certain conditions
// e.g. 3
// for-in statement
for item in shoppingList {
print("We need to buy \(item)")
// if-else Conditionals
//
//
//
//
if (item == "Eggs") {
print("we have eggs!")
} else {
print("we have Milk!")
}
}
//switch statement
var newItem = "Bread"
//switch statement
var newItem = "Bread"
switch newItem {
case "Eggs":
print("this is an Egg")
case "Milk":
print("this is Milk")
default:
print("item does not exist in the shopping List")
}