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

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.

主站蜘蛛池模板: 额敏县| 赤城县| 新沂市| 舒兰市| 游戏| 辛集市| 行唐县| 额济纳旗| 永丰县| 曲阳县| 清原| 融水| 广宁县| 三都| 理塘县| 磐石市| 江山市| 白水县| 上杭县| 阿荣旗| 罗山县| 甘泉县| 广灵县| 修文县| 怀远县| 共和县| 南靖县| 文安县| 苍南县| 太谷县| 玉树县| 临海市| 济南市| 大同县| 克拉玛依市| 永修县| 西城区| 封开县| 颍上县| 林口县| 宜兰市|