Question:

What output will be produced by the code below?

let i = 101

if case 100...101 = i {
    print("Hello, world!")
} else {
    print("Goodbye, world!")
}

 

Correct answer: "Hello, world!".

Explanation: Using if case with a range like 100...101 allows us to check whether an integer is inside that range. In this case, it checks whether the value of i (101) is inside the range of numbers 100 and 101 (inclusive), which it is, so "Hello, world!" is printed.


Keywords:

© 2017 QuizBucket.org