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 ...
随机推荐
- CURL操作
具体代码如下: <?php$curl=curl_init(); //初始化$url='http://www.ecshop.com';//curl_setopt(curl资源,选项标志,选项值)c ...
- Linux 各种软件的安装-mysql篇
作为一个长期混迹在windows圈的小白,当拿到一个新的linux服务器时,有点手足无措的赶脚.但是万事开头难嘛,Just Do It! 下面记录一下自己安装各种软件时遇到的坑.这一篇先讲mysql ...
- 昂达 v891 v1 终于 删除 windows 分区 并且恢复了容量。
参考了很多文章(最后列出重要的),却始终失败. 途中因为乱改分区表,竟然fastboot 都进不去了,当时真是欲哭无泪. 总结关键点: 1) partition.tbl不能把硬盘剩余空间全给data分 ...
- USBCAN的使用和上位机开发(MFC)
USBCAN使用手册 参见:https://blog.51cto.com/12572800/2062839 1. USB CAN软件安装与硬件接线 USB CAN是常用的CAN测试工具.它的软件资料存 ...
- pseudotime专题
review:Computational Methods for Trajectory Inference from Single-Cell Transcriptomics Tools/Algorit ...
- week02 课堂作业
测试一:(点此看原题目) 运行结果: 测试二:(点此看原题目) 运行结果: 测试三:(点此看原题目) 运行结果:
- English trip M1 - AC1 My Dream Car Teacher:Corrine
In this lesson you will learn to describe an object. 课上内容(Lesson) You want to rent a car. Go to the ...
- PHP中工厂模式与策略模式区别
策略模式需要自己动手去做,工厂模式是都准备好了你需要选择 工厂模式:有一天你决定去吃披萨,一看菜单,哦,种类很多呀,你就点了个培根披萨,过了二十分钟,你的披萨就来了就可以吃到了.但这个披萨是怎么做的, ...
- 『cs231n』通过代码理解风格迁移
『cs231n』卷积神经网络的可视化应用 文件目录 vgg16.py import os import numpy as np import tensorflow as tf from downloa ...
- hdu-4819-线段树套线段树
http://acm.hdu.edu.cn/showproblem.php?pid=4819 给出一个N*N的矩阵,每次询问一个m*m的子矩阵里的floor((maxv+minv)/2)并把中间的元素 ...