Swift program to demonstrate the one-sided range operator

bookmark

let countries = ["india", "usa", "uk", "australia"]
let len     = countries.count

print("Left sided range operator:")
for country in countries[1...] {
    print("\t",country);
}

print("Right sided range operator:")
for country in countries[...2] {
    print("\t",country);
}

 


Output:

Left sided range operator:
         usa
         uk
         australia
Right sided range operator:
         india
         usa
         uk

...Program finished with exit code