I
http://git.io/GrokSwift
print("Hello, world!")printprint("Hello, world!")print
var myVariable = 42
myVariable = 50
let myConstant = 42
let implicitInteger = 70
let implicitDouble = 70.0
let explicitDouble: Double = 70
myVariable = 42
myVariable = "42" #
var myVariable = 42
myVariable = "42" //
final int[] individualScores = [75, 43, 103, 87, 12];
int teamScore = 0;
for (int score : individualScores) {
if (score > 50) {
teamScore += 3;
} else {
teamScore += 1;
}
}
System.out.printf("%dn", teamScore);
let individualScores = [75, 43, 103, 87, 12]
var teamScore = 0
for score in individualScores {
if score > 50 {
teamScore += 3
} else {
teamScore += 1
}
}
print(teamScore)
int accumulator = 0;
for (int i = 0; i <= 4; ++i) {
accumulator += i;
}
System.out.printf("%dn", accumulator);
var accumulator = 0
for i in 0...4 {
accumulator += i
}
print(accumulator)
var accumulator = 0
for i in 0...4 {
accumulator += i
}
print(accumulator)
var accumulator = 0
for i in 0..<5 {
accumulator += i
}
print(accumulator)
var accumulator = 0
for i in 0..<5 {
accumulator += i
}
print(accumulator)
accumulator = 0
for i in range(1, 5) {
accumulator += i
}
print(accumulator)
•Safe
•Fast
•Expressive
•Safe
•Fast
•Expressive
I by Pat Hawks is licensed under a

Creative Commons Attribution 4.0 International License
Emoji provided free by Emoji One
Some content from The Swift Programming Language by Apple Inc.
I

I  Swift