iOS Swift Collections and Control Flow Control Flow With Conditional Statements Working With Switch Statements

kindly rectify

var europeanCapitals: [String] = [] var asianCapitals: [String] = [] var otherCapitals: [String] = []

let world = [ "BEL": "Brussels", "LIE": "Vaduz", "BGR": "Sofia", "USA": "Washington D.C.", "MEX": "Mexico City", "BRA": "Brasilia", "IND": "New Delhi", "VNM": "Hanoi"]

europeanCapitals.append("Brussels, Vaduz , Sofia") otherCapitals.append("Washington D.C.,Mexico City,Brasilia") asianCapitals.append("New Delhi, Hanoi") for (key, value) in world { switch key { case "BEL","LIE","BGR":print(europeanCapitals) case "IND","VNM":print(asianCapitals) default:print(otherCapitals) } }

operators.swift
var europeanCapitals: [String] = []
var asianCapitals: [String] = []
var otherCapitals: [String] = []

let world = [
    "BEL": "Brussels",
    "LIE": "Vaduz",
    "BGR": "Sofia",
    "USA": "Washington D.C.",
    "MEX": "Mexico City",
    "BRA": "Brasilia",
    "IND": "New Delhi",
    "VNM": "Hanoi"]

europeanCapitals.append("Brussels, Vaduz , Sofia")
otherCapitals.append("Washington D.C.,Mexico City,Brasilia")
asianCapitals.append("New Delhi, Hanoi")
for (key, value) in world {
    switch  key {
    case "BEL","LIE","BGR":print(europeanCapitals)
    case "IND","VNM":print(asianCapitals)
    default:print(otherCapitals)
}
}

1 Answer

kjvswift93
kjvswift93
13,433 Points
var europeanCapitals: [String] = []
var asianCapitals: [String] = []
var otherCapitals: [String] = []

let world = [
  "BEL": "Brussels", 
  "LIE": "Vaduz", 
  "BGR": "Sofia", 
  "USA": "Washington D.C.", 
  "MEX": "Mexico City", 
  "BRA": "Brasilia", 
  "IND": "New Delhi", 
  "VNM": "Hanoi"]

for (key, value) in world {
    // Enter your code below

  switch key {
    case "BEL","LIE","BGR": europeanCapitals.append(value)
    case "IND","VNM": asianCapitals.append(value)
    case "USA","MEX","BRA": otherCapitals.append(value)
    default:otherCapitals.append(value) }

    // End code
}