Scala中的几种循环

Scala中的几种循环

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
28
29
30
31
package com.anthony

/**
* @ Description:
* @ Date: Created in 20:57 09/07/2018
* @ Author: Anthony_Duan
*/
object cycle_test {


def main(args: Array[String]): Unit = {

val zimus = Array('a','b','c','d','e')

for (zimu <- zimus){
println(zimu)
}

zimus.foreach(zimu=>println(zimu))

var (num,sum) = (100,0)

while (num>0){
sum+=num
num-=1
}
println(sum)

}

}
-------------End Of This ArticleThank You For Reading-------------