看书的时候有这么一行代码:
scala> for(c<-"hello" ;i <-0 to 1) yield (c+i).toChar
res5: String = hieflmlmop
为什么会把i,f,m,m,p插到hello中间呢?
看书的时候有这么一行代码:
scala> for(c<-"hello" ;i <-0 to 1) yield (c+i).toChar
res5: String = hieflmlmop
为什么会把i,f,m,m,p插到hello中间呢?
15 回答8.1k 阅读
8 回答5.9k 阅读
1 回答4.1k 阅读✓ 已解决
3 回答2.2k 阅读✓ 已解决
2 回答3.1k 阅读
2 回答3.8k 阅读
1 回答2.1k 阅读✓ 已解决
实际上相当于一个两重循环,每次
c
先取"hello"中的一个字符,i
再从0到1,因而就是c
(c + 1).toChar
按
z
字形来读上面这个表也就是结果了。