Go语言的for和switch
2016-07-11 14:50
961 查看
package main import ( "fmt" ) //switch例子,比较返回两个字节数组字典数序先后的整数。 func Compare(a,b []byte) int{ for i := 0;i < len(a) && i < len(b);i++{ switch{ case a[i] > b[i]: return 1; case a[i] < b[i]: return -1; } } switch{ case len(a) < len(b): return -1; case len(a) > len(b): return 1; } return 0 } func main(){ //for例子 list := []string{"h","e","l","l","o"} for k,v := range list{ fmt.Printf("%d %c\n",k,v) } for k,v := range "abcdef" { fmt.Printf("%d %c\n",k,v) } //Println , printf s1 := []byte{'a','c'} s2 := []byte{'a','d'} fmt.Println(Compare(s1,s2)) }
相关文章推荐
- 安装 pytz方法
- 使用Go语言两三事
- Erlang & Go 的IO优化策略简介
- go字符串复数
- Go语言圣经(中文版)读书笔记(五)
- Go中的用组合实现继承
- 高效使用google
- go控制语句
- [2016/7/11][dp][dfs]Flood Fill Algorithm(to 4000 find the shortest path)
- goEasy消息推送,pushlet 向特写用户实时推送
- Go中map的使用
- Golang自玩项目中一个重连机制实现.
- Django的Hello World
- google_apactest_round_A_problem_D
- 开源公司黄页之 Google 开源软件推荐
- Go语言学习笔记9
- Google浏览器中的开发工具.
- Django Multiple Database
- 【在线笔试题解题报告系列】Google APAC 2017 University Test Round A
- TYVJ 2009「Poetize8」Lagoon