One-sided range

A one-sided range operator allows you to use ranges that continue as far as possible in one direction. If you want the range to continue, then this is what you would use. Let's look at a one-sided range by adding the following:

let names = ["Craig", "Teena", "Jason", "Joshua", "Myah", "Tiffany", "Kim", "Veronica", "Mikki(KK)", "Milan", "Shelby", "Kaysey"]

for name in names[2...] {
print(name)
}

You will see that all the names print in the console:

As a next step, let's add the following:

for name in names[...6] { 
 print(name) 
} 
 
// Craig 
// Teena
// Jason // Joshua // Myah // Tiffany // Kim

You should now see in the console how this update changes what is in the console:

Another useful loop is the while loop. Let's take a look at how the while loop is used.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.187.103