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 %cn",k,v)
}
for k,v := range "abcdef" {
fmt.Printf("%d %cn",k,v)
}
//Println , printf
s1 := []byte{'a','c'}
s2 := []byte{'a','d'}
fmt.Println(Compare(s1,s2))
}
最后
以上就是等待茉莉最近收集整理的关于Go语言的for和switch的全部内容,更多相关Go语言内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复