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

Closed range

Notice that, in the preceding diagram, we have numbers ranging from 10 to 20. Rather than having to write each value, we can use ranges to represent all of these numbers in shorthand form. To do this, let's remove all of the numbers in the diagram except for 10 and 20:

Now that we have removed those numbers, we need a way to tell Swift that we want to include all of the numbers that we just deleted. All the numbers in-between are where the range operator (...) comes into play. Therefore, in Playgrounds, let's create a constant called range and set it equal to 10...20:

let range = 10...20

You should see the following:

The range that we just entered says that we want the numbers between 10 and 20, as well as both 10 and 20 themselves. This type of range is known as a closed range.

Inside Playground, in the result, you will see a Show Result icon:

If you hover over the result, you will also see quick look:

Select the Show Result icon so that you can see the result:

We also have what is called a half-closed range.

主站蜘蛛池模板: 临沧市| 十堰市| 肇东市| 桃园市| 甘德县| 宁陕县| 金平| 晋宁县| 南江县| 华宁县| 安远县| 云和县| 昔阳县| 孟连| 琼海市| 仪征市| 宣化县| 临沧市| 曲松县| 长寿区| 兴国县| 凤山市| 皮山县| 漳州市| 利辛县| 根河市| 望谟县| 高唐县| 黄大仙区| 纳雍县| 东兴市| 含山县| 望城县| 西宁市| 濉溪县| 贵港市| 望谟县| 浦东新区| 阿巴嘎旗| 郴州市| 南丰县|