Scala 循环
来源:互联网 发布:苹果笔记本mac系统盘 编辑:程序博客网 时间:2024/04/28 13:54
环境: CentOS 6.3
不解释,看例子,自己琢磨。
1. While 循环
$ cat while.scala
var i = 10;
while ( i > 0 ) {
println("this is number " + i);
i = i -1;
}
$ scala while.scala
this is number 10
this is number 9
this is number 8
this is number 7
this is number 6
this is number 5
this is number 4
this is number 3
this is number 2
this is number 1
2. foreach 循环
$ cat foreach.scala
var array=new Array[String](3) //创建数组并初始化
array(0) = "hello"
array(1) = "nihao"
array(2) = "ma?"
array.foreach(arr => println(arr)) // 用foreach 循环输出数组内容 arr是指array里面每个元素的参数,scala 会推断是string
//array.foreach((arr:String) => println(arr)) //也可以显示指定arr类型
3. for 循环
$ cat for.scala
for(arg<-args)
println(arg)
$ scala for.scala this is China
this
is
China
总结,函数式文本的语法:
1 0
- Scala 循环
- scala循环
- Scala--循环
- scala while循环 for 循环
- Scala中的循环语句
- Scala之for循环
- scala的for循环
- scala for 循环
- scala函数 for循环
- scala for循环
- Scala 循环语句
- scala-for循环
- scala循环判断
- Scala for循环
- scala iterator循环遍历
- scala循环遍历
- 九.Scala 循环
- Scala for循环
- linux进程、线程常用的几个基础知识点
- 树莓派UDP通信及串口通信
- iOS开发笔记--解决UITableView中Cell重用机制导致内容出错的方法总结
- 使用 Java 实现 Comet 风格的 Web 应用
- MySQL之alter语句用法总结
- Scala 循环
- BspTree分区二叉树
- T-SQL查询高级—SQL Server索引中的碎片和填充因子
- TC_SRM_621_DIV2
- Mysql、Oracle 中的数据类型与java中的数据类型对应表
- Ubuntu 12.04 国内更新源列表
- 编写程序是以下步骤的一个往复过程:
- Sapphire手机按钮检测控件Sapphire Buttons Utility介绍
- Git命令学习笔记