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 ...
随机推荐
- vuex中的辅助函数 mapState,mapGetters, mapActions, mapMutations
1.导入辅助函数 导入mapState可以调用vuex中state的数据 导入mapMutations可以调用vuex中mutations的方法 四个辅助函数 各自对应自己在vuex上的自己 2.ma ...
- vue init webpack nameXXX 报错问题:
vue新建demo项目报错如下: M:\lhhVueTest>vue init webpack L21_VueProject vue-cli · Failed to download repo ...
- GRCh38基因组和注释文件探究
ensembl/release91: cat Homo_sapiens.GRCh38.91.gtf | grep -v "#" | cut -f9 | cut -f1,3,6,8 ...
- vs2013安装及opencv3.0的配置
vs2013的安装改善计划,不勾选. Windows8 和 windows phone不勾选 然后进行解压安装.(我安装在了e盘的次级目录) 安装完成,点击“启动” 登陆界面,点击“以后再说”. ...
- exam_review to M1
1. 情态动词,尤其是can/can’t,should/shouldn’t. for example: You should have washed the wound.你应该已经洗好了伤口 Well ...
- JS获取系统时间--JavaScript基础
1.网页中实时显示当前时间 <!DOCTYPE html><html lang="en"><head> <meta charset=&qu ...
- .net WinForm 的数据绑定
.net WinForm 的数据绑定相当灵活 http://www.cnblogs.com/ydong/archive/2006/04/22/381847.html 原来只知道 Control 类上的 ...
- p1211 Prime Cryptarithm
直接深搜+检验. #include <iostream> #include <cstdio> #include <cmath> #include <algor ...
- 纯js无缝滚动
HTML代码 <!--父容器要使用overflow: hidden;--> <div id="imgsList" style="height:150px ...
- PHP单例模式 demo
<?php class single{ static public $db; private function __construct(){ }; static function getinst ...