zoukankan      html  css  js  c++  java
  • if-else,switch,for循环

    if-else语句

    //if-else
    package main
    
    func main() {
    	//a:=9
    	//1 基本使用
    	//if a>10{
    	//	fmt.Println("大于10")
    	//}else {
    	//	fmt.Println("小于等于10")
    	//}
    
    	//2 if -else if -else
    	//if a>10{
    	//	fmt.Println("大于10")
    	//}else if a==10 {
    	//	fmt.Println("等于10")
    	//}else {
    	//	fmt.Println("小于10")
    	//}
    
    	//3 不能换行(go语言每一行结尾,需要加一个;  ,每当换行,会自动加;)
    	//if a>10{
    	//	fmt.Println("大于10")
    	//}else if a==10 {
    	//	fmt.Println("等于10")
    	//}else
    	//{
    	//	fmt.Println("小于10")
    	//}
    
    	//4 条件里可以进行初始化操作(有作用域范围的区别)
    	//a:=10;
    	//if a<10{
    	//if a:=10;a<10{
    	//	fmt.Println("xxx")
    	//}else {
    	//	fmt.Println("yyyy")
    	//}
    	//fmt.Println(a)
    
    	//fmt.Println(a)
    }
    

    switch语句

    //switch多条件选择
    
    package main
    
    import "fmt"
    
    func main() {
    	//1 switch基本使用
    	//a:=10
    	//switch a {
    	//case 1:
    	//	fmt.Println("1")
    	//case 2:
    	//	fmt.Println("2")
    	//case 9:
    	//	fmt.Println("9")
    	//case 10:
    	//	fmt.Println("10")
    	//
    	//}
    
    	//2 default的基本使用
    	//a:=16
    	//switch a {
    	//case 1:
    	//	fmt.Println("1")
    	//case 2:
    	//	fmt.Println("2")
    	//case 9:
    	//	fmt.Println("9")
    	//case 10:
    	//	fmt.Println("10")
    	//default:
    	//	fmt.Println("不知道")
    	//
    	//}
    
    	//3 多条件
    	//a:=16
    	//switch a {
    	//case 1,2,3:
    	//	fmt.Println("1")
    	//case 4,5,6:
    	//	fmt.Println("2")
    	//case 7,9:
    	//	fmt.Println("9")
    	//case 10,16:
    	//	fmt.Println("10")
    	//default:
    	//	fmt.Println("不知道")
    	//
    	//}
    
    
    	////4 无表达式
    	//a:=3
    	//switch  {
    	//case a==1 || a==3:
    	//	fmt.Println("1")
    	//case a==4 || a==5:
    	//	fmt.Println("2")
    	//default:
    	//	fmt.Println("不知道")
    	//
    	//}
    
    	//5 fallthrough,无条件执行下一个case
    	a:=3
    	switch  {
    	case a==1 || a==3:
    		fmt.Println("1")
    		fallthrough //无条件执行下一个case
    	case a==4 || a==5:
    		fmt.Println("2")
    	default:
    		fmt.Println("不知道")
    
    	}
    
    
    }
    
    

    for循环

    //循环 (只有for循环 没有while 以及 do while)
    package main
    
    import "fmt"
    
    func main() {
    	//1 基本语法
    	//for 初始化;条件判断;自增/自减{循环体内容}  三部分都可以省略
    
    	//for i:=0;i<10;i++ {
    	//	fmt.Println(i)
    	//}
    
    	//2 省略第一部分(初始化)(注意:作用域范围就不太一样了)
    	//i:=0
    	//for ;i<10;i++ {
    	//	fmt.Println(i)
    	//}
    
    	////3 省略第三部分
    	//for i:=0;i<10; {
    	//	i++ //写在前面是从1开始
    	//	fmt.Println(i)
    	//	//i++  //写在后面是从0开始
    	//}
    
    	//4 省略第一和第三部分(其实看起来不就是while循环吗)
    	//i:=0
    	//for i<10 {
    	//	i++ //写在前面是从1开始
    	//	fmt.Println(i)
    	//	//i++  //写在后面是从0开始
    	//}
    
    	//5 for 条件 {}
    	//for true{
    	//	fmt.Println("1")
    	//}
    
    	//6 死循环
    	//for {
    	//	fmt.Println("1")
    	//}
    
    	//7 break和continue
    	for {
    		fmt.Println("1")
    		break
    		//continue
    	}
    }
    
    
  • 相关阅读:
    github新手使用指南
    Nacos(五):多环境下如何“读取”Nacos中相应的配置
    Nacos(四):SpringCloud项目中接入Nacos作为配置中心
    Nacos:Nacos与OpenFeign的对接使用
    解决IDEA的maven项目 添加依赖后Reimport无反应
    SpringCloud项目中接入Nacos作为注册中心
    Nacos 使用
    SpringCloud教程 | 第十三篇: 断路器聚合监控(Hystrix Turbine)
    C# Task总结(Action,Func,委托)
    C# Task总结(异步操作+并行)
  • 原文地址:https://www.cnblogs.com/yafeng666/p/12748474.html
Copyright © 2011-2022 走看看