/此次省略1000字、
var myString = "Hello world! - swift.jsrun.net"
print(myString)
let implicitInteger=70
let implicitDouble=70
let explicitDouble:Double=70
let label = "The width is"
let width = 94
let widthLabel = label + String (width)
let apples = 3
let oranges = 5
let appleSummary = "I have \ (apples) apples."
let fruitSummary = "I have \ (apples + oranges) pieces of fruit."
var shoppingList = ["catfish", "water","tulips","blue paint"]
shoppingList [1] = "bottle of water"
var occupations = [
"Malcolm": "Captain",
"Kaylee":"Mechanic",
]
occupations I" Jaynem] = mPublic Relations"
let emptyArray = [String] ()
let emptyDictionary = [String: Float] ()
shoppingList = []
occupations =[:]
let individualscores = [75,43,103,87,12]
var teamScore = 0
for score in individualScores {
if score > 50 {
teamScore += 3
} else {
teamScore += 1
}
}
print (teamScore)
var optionalName: String? = "John Appleseed"
var greeting = "Hello!"
if let name = optionalName {
greeting = "Hello, \ (name)"
}
let nickName: String? = nil
let fullName: String = "John Appleseed"
let informalGreeting = "Hi \ (nickName ?? fullName)"
let vegetable = "red pepper"
switch vegetable {
case "celery":
print ("Add some raisins and make ants on a log.")
case "cucumber", "watercress":
print ("That would make a good tea sandwich.")
case let x where x. hasSuffix ("pepper"):
print ("Is it a spicy \(x)?")
default:
print ("Everything tastes good in soup. ")
}
let interestingNumbers = [
"Prime": [2, 3, 5, 7, 11, 13],
"Fibonacci": [1, 1, 2, 3, 5, 8],
"Square":[1, 4, 9, 16, 25],
]
var largest =0
for (kind, numbers) in interestingNumbers {
for number in numbers{
if number > largest{
largest = number
}
}
}
print(largest)
var n = 2
while n< 100{
n=n* 2
}
Print (n)
var m = 2
repeat {
m = m * 2
}While m < 100
print (m)
var total = 0
for i in 0.. <4 {
totaL t+= i
}
print(total)
func greet (name: String, day: String) -> String {
return "Hello \ (name), today is \ (day)."
}
greet ("Bob", day: "Tuesday")