官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 溧阳市| 林州市| 新邵县| 绍兴县| 安新县| 新兴县| 肥东县| 盘锦市| 桂平市| 陈巴尔虎旗| 灵丘县| 宁南县| 塘沽区| 绍兴县| 潼南县| 正宁县| 晋宁县| 宜兰县| 武汉市| 柘荣县| 江安县| 合阳县| 同德县| 逊克县| 海宁市| 社旗县| 泸水县| 大余县| 甘南县| 绥棱县| 元阳县| 崇州市| 通化县| 阜宁县| 平顺县| 临夏市| 丰顺县| 上思县| 修水县| 阜城县| 玛多县|