Skip to content

Latest commit

 

History

History
32 lines (31 loc) · 696 Bytes

control-flow-conditional.md

File metadata and controls

32 lines (31 loc) · 696 Bytes

Control-Flow & Conditionals

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")
}