Swift是什么?Swift号称是简单、快速的编译型脚本语言,适用于在多核计算机,集群,云与超级计算机上运行。
联合数组在声明时,可使用auto关键字而不指定任何一个原生类型作key,由语言决定:
|
1
2
3
4
5
6
7
8
9 |
int[auto] array;foreach
i in
[1:10] { array << (i*2);}foreach
v in
array { trace(v);} |
保存为文本文件hello.swift,在终端中执行
|
1 |
swift hello.swift |
输出:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 |
Swift 0.94.1 swift-r7114 cog-r3803RunID: 20140603-1132-ba5mh8d6Progress: time: 星期二, 03 六月 2014 11:32:59 +0800SwiftScript trace: 12SwiftScript trace: 18SwiftScript trace: 8SwiftScript trace: 10SwiftScript trace: 14SwiftScript trace: 2SwiftScript trace: 16SwiftScript trace: 4SwiftScript trace: 20SwiftScript trace: 6Final status: 星期二, 03 六月 2014 11:32:59 +0800 |
从结果看出,foreach循环并不是顺序执行的。
原文地址:http://www.cnblogs.com/sban/p/3765502.html