-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathContents.swift
56 lines (43 loc) · 1.03 KB
/
Contents.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//Control Flow
var myDict = ["LOL": "Laugh out loud", "LMAO": "Laugh my ass off"]
var menu: [String] = ["idlis", "sambhar", "dosa", "samosa", "raj kachori", "papdi chaat"]
//for loop
for foodItem in menu{
print("Raghav loves eating \(foodItem)")
}
//if else
var number: Int = 12
if number > 13{
print("I am big")
}
else{
print("I am small")
}
//=======================================================================
//Switch Case
let vegetable: String = "red pepper"
switch vegetable{
case "celery":
print("Add some raisins and make ants on a log")
case "cucumber", "watercress":
print("This is great for tea sandwhiches")
case let x where x.hasSuffix("pepper"):
print("Is it a spicy \(x)?")
default:
print("everything tastes fine")
}
//For loops over dictionaries
for (shortForm, actual) in myDict{
print("\(shortForm) = \(actual)")
}
var total = 0
for i in 0..<4{
total+=i
}
print(total)
//While loop
var count = 0
while count < 5{
print("Hello")
count+=1
}