Skip to content

Instantly share code, notes, and snippets.

@shankartshinde
Created May 8, 2018 06:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shankartshinde/22b2c3763536dc245bd9753f8b20176a to your computer and use it in GitHub Desktop.
Save shankartshinde/22b2c3763536dc245bd9753f8b20176a to your computer and use it in GitHub Desktop.
print("Q:1:")
let val = 10.2
print("\(val) of type \(val.description)")
var numbers = [1,2,3]
numbers+=[4]
print(numbers)
print("7:")
let i = 3
switch i {
case 1:
print("Number was 1")
case 2:
print("Number was 2")
case 3:
print("Number was 3")
}
print("8:")
let names = ["Shankar","Archana"]
for i in 0...names.length
{
print("Hello \(names[i])!")
}
print("9:")
let num = 16.0
print(" \(num) squared is \(num * num), and its square root is \(sqrt(num)) !")
print("10:")
for name in names
{
name = name.uppercased()
print("Hello \(names)!")
}
print("12:")
let names12 = ["Shankar","Sulaco","Enterprise","Galactica"]
for name in names12 where name.hasPrefix("S") {
print("Hello \(name)")
}
print("13:")
let names13 = ["Yugan","Archana"]
let names13Result = names12 + names13
print(names13Result)
print("14:")
func sayHello(to name:String)->String {
return "Howdy! \(name)"
}
print("\(sayHello(to:"Shanky"))")
print("15:")
if let name = names12.last {
print("\(name)")
}
print("16:")
let names16 = [String]()
names16.append("Source")
names16.append("C++")
names16.append("Objective-C")
print("17:")
var i = 2
// NOTE : do ... while does not exist, There is repeat .. while is there
repeat {
print(i)
i *= 2
}while(i < 128)
print("18:")
enum Weather {
case cloudy
case temprature
case windy(speed:Int)
}
let today = Weather.windy(speed: 10)
switch today {
case .cloudy,.temprature :
print("It is not windy")
case .windy(let wind) where wind >= 10 :
print("This is windy high speed")
}
print("19:")
let myStr : String
myStr = "Hello"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment