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 ...
随机推荐
- Java的ResultSet中rs.next()含义
- Oracle10g 回收站及彻底删除table : drop table xx purge
drop后的表被放在回收站(user_recyclebin)里,而不是直接删除掉.这样,回收站里的表信息就可以被恢复,或彻底清除. 1.通过查询回收站user_recyclebin获取被删除的表信息, ...
- python调试 设置断点
1在所需要调试的地方加入如下代码: import pdb pdb.set_trace() 2调试代码常用命令: 实例请见参考文献: 1http://www.cnblogs.com/qi09/ar ...
- 【HDOJ】4579 Random Walk
1. 题目描述一个人沿着一条长度为n个链行走,给出了每秒钟由i到j的概率($i,j \in [1,n]$).求从1开始走到n个时间的期望. 2. 基本思路显然是个DP.公式推导也相当容易.不妨设$dp ...
- git删除中文文件
git中出现如下代码时,是因为文件中包含中文.而且我们也无法用 git rm name 命令来删除该文件. deleted: "chrome_plugin/source_file/iHub\ ...
- 1306.Sequence Median(堆排序)
1306 URAL真是没水题 以为简单的排序就好了 ME 内存限制很紧 堆排序 或者 STL 用堆排序做的 正好复习一下 都忘了 #include <iostream> #include ...
- 大四实习准备3_java多线程
4.25.27无耻地懒散了.....26号陪女朋友去了.今天28号,继续加油! 2015-4-28 Java 多线程 (java中类不能多继承,可以多层继承:接口则都可以) 定义和创建: 方法一:继承 ...
- 结构体UT_LIST_ADD_LAST
使用 UT_LIST_ADD_LAST(list, buf_pool->free, (&block->page)); /****************************** ...
- php 生成类的对象 $a=new test();
程序 <?php class test { ... } $a=new test(); 1.BNF 范式 start: variable '=' expr ';' expr: new_expr ; ...
- IDE模式下安装Windows 7强行改回ACHI后不断重启的解决方法
问题描述:用U盘启动进PE装的Win7,由于PE认不出硬盘,只好进BIOS设置硬盘模式为IDE才安装上.结果安装完系统后,在BIOS中强行修改硬盘模式为ACHI模式后,Win7开机不断重启,进不了系统 ...