Explain What is half-open range operator?

devquora
devquora

Posted On: Feb 22, 2018

 

Half-Open Range Operator: It is an operator (a<b) that is used to defines a range that runs from a to b but it doesn’t contain b. The reason for its name that is half-open is that it does not contains its last value, just have its first value. The value of 'a' compulsory is not greater than b in the closed ranged operator. The resulting range will be empty in the case of a is equal to b.

It is useful when you are working with zero-based lists like arrays where it is useful to calculate the length of the list. For example:

let names = ["Alley", "Anna", "Jack", "Brian"]
let count = names.count
for i in 0..<count span id="docs-internal-guid-b356581b-7fff-3109-a868-e60b14559aae">count
print("Person \(i + 1) is called \(names[i])")
} // Person 1 is called Alley, Person 2 is called Anna, Person 3 is called Jack, Person 4 is called Brian

    Related Questions

    Please Login or Register to leave a response.

    Related Questions

    Swift Interview Questions

    What is IOS Swift?

    iOS swift is an intuitive and stalwart language for the iOS. It is joyful to deal with the writing stuff in Swift. It is very advanced and its syntax is also concise and expressive too...

    Swift Interview Questions

    What is Dictionary in Swift?

    It enables you to store the key-value pairs and access the value by providing the key.It is similar to that of the hash..

    Swift Interview Questions

    Explain Enum in Swift?

    Basically, it is a type that contains a group of various related values under the same umbrella...