A Tour of Go Switch evaluation order
Switch cases evaluate cases from top to bottom, stopping when a case succeeds.
(For example,
switch i {
case 0:
case f():
}
does not call f if i==0.)
Note: Time in the Go playground always appears to start at 2009-11-10 23:00:00 UTC, a value whose significance is left as an exercise for the reader.
package main import (
"fmt"
"time"
) func f(num *int) int{
(*num) = (*num) +
return (*num);
}
func main() {
num :=
total :=
switch total {
case f(&num):
fmt.Println(num)
case f(&num):
fmt.Println(num)
case f(&num):
fmt.Println(num)
}
fmt.Println("When's Saturday?")
today := time.Now().Weekday()
switch time.Saturday {
case today + :
fmt.Println("Today.")
case today + :
fmt.Println("Tomorrow.")
case today + :
fmt.Println("In tow days.")
default:
fmt.Println("Too far away.")
}
}
case中的语句可以是返回值的语句
A Tour of Go Switch evaluation order的更多相关文章
- A Tour of Go Switch with no condition
Switch without a condition is the same as switch true. This construct can be a clean way to write lo ...
- A Tour of Go Switch
You probably knew what switch was going to look like. A case body breaks automatically, unless it en ...
- [ES7] Descorator: evaluated & call order
When multiple decorators apply to a single declaration, their evaluation is similar to function comp ...
- Hibernate Validator 6.0.9.Final - JSR 380 Reference Implementation: Reference Guide
Preface Validating data is a common task that occurs throughout all application layers, from the pre ...
- PHP资源列表
一个PHP资源列表,内容包括:库.框架.模板.安全.代码分析.日志.第三方库.配置工具.Web 工具.书籍.电子书.经典博文等等. 初始翻译信息来自:<推荐!国外程序员整理的 PHP 资源大全& ...
- 【PHP资源】PHP 资源大全
看到这篇文章不错,转来收藏 依赖管理 依赖和包管理库 Composer/Packagist:一个包和依赖管理器 Composer Installers:一个多框架Composer库安装器 Pickle ...
- Recover lost Confluence password
confluence重置admin密码 复方法: 1. 运行此sql 找到你的管理员帐户: select u.id, u.user_name, u.active from cwd_user u joi ...
- 【PHP开发】国外程序员收集整理的 PHP 资源大全
依赖管理 依赖和包管理库 Composer/Packagist:一个包和依赖管理器 Composer Installers:一个多框架Composer库安装器 Pickle:一个PHP扩展安装器 其他 ...
- python3.4 build in functions from 官方文档 翻译中
2. Built-in Functions https://docs.python.org/3.4/library/functions.html?highlight=file The Python i ...
随机推荐
- linux下mysql修改数据库账户root密码
#先停止mysql,再运行下一句 $ mysqld_safe --user=mysql --skip-grant-tables --skip-networking & $ mysql -u r ...
- jmeter HTTP信息头管理器使用一例
最近在测试过程中遇到一个问题,被测系统会检测http header:如果不包含制定内容会引发302跳转操作,从而是测试达不到效果.解决办法,增加http 信息头管理器,直接上图 此处注意: 1.此处“ ...
- EL表达式对数组、集合操作
el表达式是通过${key}的方式获取对象中的值.在el表达式中有如下几个隐含的对象,pageScope,requestSope,sessionScope,applicationScope,如果要取$ ...
- android应用崩溃的调试方法(c++ lib so文件库崩溃)
android调试工具addr2line使用: 1.将ndk中的arm-linux-androideabi-addr2line可执行文件的路径加入配置文件~/.bashrc中,例如: export P ...
- live555源码研究(五)------DynamicRTSPServer类
一.类DynamicRTSPServer作用 1,提供RTSP服务 二.类DynamicRTSPServer继承关系图
- Node.js学习(11)----HTTP服务器与客户端
Node.js 标准库提供了 http 模块,其中封装了一个高效的 HTTP 服务器和一个简易的HTTP 客户端.http.Server 是一个基于事件的 HTTP 服务器,它的核心由 Node.js ...
- PHP的(Thread Safe与Non Thread Safe)
在安装xdebug到时候你会有有TS和NTS版本的选择,在以前还有VC6和VC9的版本.如果你没有根据你目前的服务器的状况选择对应的版本的话,那么xdebug是安装不成功的. 一.如何选择 php5. ...
- C# 自定义光标 WaitCursor
一种: 把图像文件放到项目的文件夹中 1 如果图像文件是.cur格式: Cursor cur=new Cursor(文件名); this.cursor=cur; 两句话 就完事 2 如果图像文件是其他 ...
- 手机通过WIFI连上ZXV10 H618B路由器但不能上网问题的解决
前几天朋友帮忙拿到一个ZXV10 H618B路由器,一看需要12V供电,还好以前留下一个12V输出的DC充电器,关键时刻用上了,先大概下载了此路由器的用户手册,发现原来是08年的产品,都5年了. 开始 ...
- android.util.AndroidRuntimeException: requestFeature() must be called before adding content 错误解决方法
Activity全屏,网上的代码如下:protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstance ...