learning scala control statement
1 .if satement
与其它语言不同的是,scala if statement 返回的是一个值
scala> val a = if ( 6 > 0 ) 1 else -1
a: Int = 1
2. while statement
3. do.. while statement
4 for statement
for ( 变量 <- 表达式 ) { 语句块};
scala> for ( i <- 1 to 3 ) println(i)
1
2
3
scala> for ( i <- Array(3,4,5) ) println(i)
3
4
5
scala> for ( i <- 1 to 5 if i%2 == 0 ) println(i)
2
4
scala> for ( i <- 2 to 4; j <- 4 to 6 ) println( i * j)
8
10
12
12
15
18
16
20
24
yield 后的语句块中最后一个表达式的值,作为每次循环的返回值,如下所示:
fortest: scala.collection.immutable.IndexedSeq[Unit] = Vector((), (), (), (), (), (), (), (), ())
fortest: scala.collection.immutable.IndexedSeq[Int] = Vector(8, 10, 12, 12, 15, 18, 16, 20, 24)
learning scala control statement的更多相关文章
- 增强学习(Reinforcement Learning and Control)
增强学习(Reinforcement Learning and Control) [pdf版本]增强学习.pdf 在之前的讨论中,我们总是给定一个样本x,然后给或者不给label y.之后对样本进行 ...
- 深度学习国外课程资料(Deep Learning for Self-Driving Cars)+(Deep Reinforcement Learning and Control )
MIT(Deep Learning for Self-Driving Cars) CMU(Deep Reinforcement Learning and Control ) 参考网址: 1 Deep ...
- [Reinforcement Learning] Model-Free Control
上篇总结了 Model-Free Predict 问题及方法,本文内容介绍 Model-Free Control 方法,即 "Optimise the value function of a ...
- Scala Control Structures
Scala之Control Structures 一.前言 前面学习了Scala的Numbers,接着学习Scala的Control Structures(控制结构). 二.Control Struc ...
- learning scala Function Recursive Tail Call
可以使用scala库,可以从字面上看出是在调用 递归函数: code import scala.util.control.TailCalls._ val arrayDonuts: Array[Stri ...
- Andrew Ng机器学习公开课笔记–Reinforcement Learning and Control
网易公开课,第16课 notes,12 前面的supervised learning,对于一个指定的x可以明确告诉你,正确的y是什么 但某些sequential decision making问题,比 ...
- learning scala 数组和容器
数组:可变的,可索引的,元素具有相同类型的数据集合 一维数组 scala> val intValueArr = new Array[Int](3)intValueArr: Array[Int] ...
- learning scala read from file
scala读文件: example: scala> import scala.io.Sourceimport scala.io.Source scala> var inputFile ...
- learning scala write to file
scala 写文件功能: scala> import java.io.PrintWriterimport java.io.PrintWriter scala> val outputFile ...
随机推荐
- SqlServer中exists和in的区别
1.in 2.exists
- Codeforces 1062 E - Company
E - Company 思路: 首先,求出每个点的dfs序 然后求一些点的公共lca, 就是求lca(u, v), 其中u是dfs序最大的点, v是dfs序最小的大点 证明: 假设o是这些点的公共lc ...
- 微信小程序动态更改样式
获取列表长度(动态渲染),当长度>x时添加内联样式并绑定数据{{}},通过js动态更改{{}}
- 响应式图片 (responsive image)
更新 : 2019-02-21 除了写 srcset sizes 还有一种 x1, x2, x3, x4 的写法. 我们对比一下 假设 pc 希望是 1000w mobile 希望是 300w siz ...
- 自动化部署之jenkins及简介
一.什么是持续集成? (1)Continuous integration(CI) 持续集成是一种软件开发实践,即团队开发成员经常集成他们的工作,通常每个成员至少集成一次,也就意味着每天可能会发生多次集 ...
- layui: 子iframe关闭/传值/刷新父页面
https://www.cnblogs.com/jiqing9006/p/5135697.html layer iframe层的使用,传参 父层 <div class="col-x ...
- python安装pandas和lxml
一.安装python 二.安装pip 三.安装mysql-connector(window版):下载mysql-connector-python-2.1.3,解压后进入目录,命令安装:pip inst ...
- 1.2 面向对象 Object-oriented
前导课程 1.UML(统一建模语言) 2.OOAD Concept(Object-oriented Analysis and Design 概念) 3.Design Pattern(设计模式) 4.面 ...
- MIR7预制发票扣除已经预制的数量(每月多次预制,未即时过账)
业务场景见抬头,有没有标准的解决方案就不说了,也没去考虑... 这个增强还是SAP老表提供的,感谢,省了不少时间. INCLUDE:LMR1MF6S 最后的位置 ENHANCEMENT ZMIR7_0 ...
- ThinkPHP3自动加载公共函数文件
7d 根目录 ├─Application 应用目录 │ ├─Common 公共模块 │ │ ├─Common 公共函数文件目录 │ │ │ ├─index.html │ │ ├─Config 配置文件 ...