mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Implement the syntax 'if x then y else z', which evaluates to 'y' if 'x' is true or 'z' if 'x' is false. 'x' must be a valid logic value, and 'y' and 'z' must be implicitly convertible to a common type. Swift SVN r4407
22 lines
302 B
Swift
22 lines
302 B
Swift
// RUN: %swift -i %s | FileCheck %s
|
|
|
|
// CHECK: 1
|
|
// CHECK: 2
|
|
// CHECK: fizz
|
|
// CHECK: 4
|
|
// CHECK: buzz
|
|
// CHECK: fizz
|
|
// CHECK: 7
|
|
// CHECK: 8
|
|
// CHECK: fizz
|
|
// CHECK: buzz
|
|
for i in 1..11 {
|
|
println(
|
|
if i % 3 == 0
|
|
then "fizz"
|
|
else if i % 5 == 0
|
|
then "buzz"
|
|
else
|
|
"\(i)")
|
|
}
|