当前位置: 首页 > news >正文

重庆博达建设集团股份有限公司网站西安seo外包行者seo06

重庆博达建设集团股份有限公司网站,西安seo外包行者seo06,建立手机个人网站,好听的建筑公司名字大全一、if-else条件判断语句 Go中的if-else条件判断语句跟C差不多。但是需要注意的是,Go中强制规定,关键字if和else之后的左边的花括号"{“必须和关键字在同一行,若使用了else if结构,则前段代码快的右花括号”}"必须和关…

一、if-else条件判断语句

  • Go中的if-else条件判断语句跟C++差不多。但是需要注意的是,Go中强制规定,关键字if和else之后的左边的花括号"{“必须和关键字在同一行,若使用了else if结构,则前段代码快的右花括号”}"必须和关键字else if在同一行。
  • Go和C++不同的是,条件判断语句不需要小括号"()"括起来
package mainimport "fmt"func main() {var num int = 100if num == 0{//{必须同一行fmt.Println("aaaaaa")}else if num == 10{//必须同一行fmt.Println("bbbbbb")}else if num == 100{fmt.Println("cccccc")}else{fmt.Println("eeeeeeee")}
}
  • 与C++不同的特殊写法,num:=10是一个语句,执行完之后,num==0才是判断表达式
    package mainimport "fmt"func main() {if num:=10; num==0 { //{必须同一行fmt.Println("aaaaaa")}
    }
    

二、switch-case语句

  • 与C++不同的是,在Go语言中,case是一个独立的代码块,执行完毕后并不会紧接着执行下一个case,所以不需要执行完一个case之后break;但是为了兼容一些移植代码,依然加入了fallthough关键字来实现执行完case语句之后紧接着执行下一个case语句。
package mainimport ("fmt"
)func main() {s := "hello"i := 15switch {case s == "hello":fmt.Println("hello")fallthroughcase s == "world":fmt.Println("world")fallthrough//强行执行下个case语句case i >= 15 && i < 20://分支可以用表达式fmt.Println("!!!!呀呀呀")default:fmt.Println("bbbbb")}str2 := "math"switch  str2{case "hhhh","math"://一个分支可以对应多个值fmt.Println("math")fallthroughcase "aaaaa":fmt.Println("math222")case "cccc":fmt.Println("math333333")fallthroughdefault:fmt.Println("qqqqqqq")}
}

结果:在这里插入图片描述

三、for循环语句

  • 与C++不同,Go语言中的循环语句只支持for关键字,并不支持while和do-while结构

  • 例子:

    package mainimport "fmt"func main() {for i:= 0; i < 10; i++{fmt.Printf(" %d ",i)}
    }
    

    结果:在这里插入图片描述

  • for的初始语句可以被忽略

  • for的条件表达式也可以被忽略

  • for只有一个条件的循环

    package mainimport "fmt"func main() {//1.忽略for的初始语句i := 0for ; i<10 ; i++{fmt.Printf(" %d ",i)}fmt.Println()//2.忽略for的条件表达式for j:=0; ;j++{if j > 10{break}fmt.Printf(" %d ",j)}fmt.Println()//3.for忽略第三条语句for j:=0;j<10; {fmt.Printf(" %d ",j)j++}fmt.Println()//4.for只有一个条件的循环var k int=0for k <= 10{fmt.Printf(" %d ",k)k++}
    }
    

    结果:在这里插入图片描述

  • for也可以无限循环

    package mainimport "fmt"func main() {//4.for实现无限循环for ; ; {fmt.Printf("aaa")}
    }
    

四、goto/break/continue跳出循环

1.goto

  • goto关键字是跳出多层循环,跳转到循环外面,执行标签内的语句
package mainimport "fmt"func main() {for i:=0; i<10; i++{for j:=0; j<10; j++{fmt.Printf(" i:%d ", i)fmt.Printf(" j:%d ", j)if j==3{goto goHereLa //跳出循环,跳转到标签语句}}}fmt.Println("\n不会到这噢,直接跳过,去goHereLa标签内")//不会打印return //手动返回,避免函数执行进入了标签代码中goHereLa:fmt.Println("\nthere le la la la,到这啦")
}

结果:在这里插入图片描述

2.break

  • break和goto一样,可以跟上标签,但是表示退出某个标签对应的代码块,标签要求必须定义在对应for, switch和select代码块上方
package mainimport "fmt"func main() {goHereLa:for i:=0; i<10; i++{for j:=0; j<10; j++{fmt.Printf(" i:%d ", i)fmt.Printf(" j:%d ", j)if j==3{break goHereLa //跳出标签goHereLa里的代码块。即跳出循环外}}}fmt.Println("\n到这啦,循环语句外面")//会打印
}

结果:
在这里插入图片描述

3.continue

  • Go中的continue和C++中并没有什么不一样,都是跳出本次循环继续下次循环。但是多加了一个功能,即也可以像break一样加上标签,表示开始标签对应的循环,并仅限于for循环中使用
package mainimport "fmt"func main() {
goHereLa:for i:=0; i<5; i++{fmt.Printf("\n i:%d ", i)for j:=0; j<10; j++{fmt.Printf(" j:%d ", j)if j==3{continue goHereLa //跳出标签goHereLa里的代码块。即跳出本次循环,继续下次循环}fmt.Println("当j是3之后不会打这个噢,直接跳出本次循环啦")}}fmt.Println("\n到这啦,循环语句外面")
}

结果:
在这里插入图片描述


文章转载自:
http://dinncovaaljapie.ssfq.cn
http://dinnconematicidal.ssfq.cn
http://dinncobunyan.ssfq.cn
http://dinncocabalism.ssfq.cn
http://dinncoflurry.ssfq.cn
http://dinncobevin.ssfq.cn
http://dinncocommunionist.ssfq.cn
http://dinnconovillo.ssfq.cn
http://dinncoghoulish.ssfq.cn
http://dinnconagpur.ssfq.cn
http://dinncoanergy.ssfq.cn
http://dinncopisciculture.ssfq.cn
http://dinncoinnersole.ssfq.cn
http://dinncoimpedance.ssfq.cn
http://dinncocottus.ssfq.cn
http://dinncoskinny.ssfq.cn
http://dinncoroughhearted.ssfq.cn
http://dinncomultihull.ssfq.cn
http://dinncolipogrammatic.ssfq.cn
http://dinncoincoordinately.ssfq.cn
http://dinncosuperman.ssfq.cn
http://dinncokhz.ssfq.cn
http://dinncoreplant.ssfq.cn
http://dinncourediospore.ssfq.cn
http://dinncohypermnesis.ssfq.cn
http://dinncomurdabad.ssfq.cn
http://dinncotraymobile.ssfq.cn
http://dinncosaxtuba.ssfq.cn
http://dinncootis.ssfq.cn
http://dinncopsycology.ssfq.cn
http://dinncoembankment.ssfq.cn
http://dinncocontestation.ssfq.cn
http://dinncofelly.ssfq.cn
http://dinncotouched.ssfq.cn
http://dinncochristianlike.ssfq.cn
http://dinncoarrowworm.ssfq.cn
http://dinncosagoyewatha.ssfq.cn
http://dinncobarcelona.ssfq.cn
http://dinncodantean.ssfq.cn
http://dinncojungli.ssfq.cn
http://dinncoyirr.ssfq.cn
http://dinncoinscriptive.ssfq.cn
http://dinncoterrorization.ssfq.cn
http://dinncovolcanist.ssfq.cn
http://dinncotiglon.ssfq.cn
http://dinncozoogeographer.ssfq.cn
http://dinncojetavator.ssfq.cn
http://dinncofleury.ssfq.cn
http://dinncomilitiaman.ssfq.cn
http://dinncosectary.ssfq.cn
http://dinncoorrery.ssfq.cn
http://dinncosubtitling.ssfq.cn
http://dinncoseismoscope.ssfq.cn
http://dinncochasteness.ssfq.cn
http://dinncophiz.ssfq.cn
http://dinncoamino.ssfq.cn
http://dinncothoroughgoing.ssfq.cn
http://dinncoconcretist.ssfq.cn
http://dinncosemicontinua.ssfq.cn
http://dinncowrangell.ssfq.cn
http://dinncodischarger.ssfq.cn
http://dinnconyc.ssfq.cn
http://dinncowlan.ssfq.cn
http://dinncopurposely.ssfq.cn
http://dinncopalaver.ssfq.cn
http://dinncorectangular.ssfq.cn
http://dinncosanguineous.ssfq.cn
http://dinncoevan.ssfq.cn
http://dinncomonorail.ssfq.cn
http://dinncomisinform.ssfq.cn
http://dinncoresidence.ssfq.cn
http://dinncogenevan.ssfq.cn
http://dinncoerwin.ssfq.cn
http://dinncodissimilarity.ssfq.cn
http://dinncobeehive.ssfq.cn
http://dinncosonneteer.ssfq.cn
http://dinncoostler.ssfq.cn
http://dinncoelectroslag.ssfq.cn
http://dinncosportful.ssfq.cn
http://dinncointerocular.ssfq.cn
http://dinncopompey.ssfq.cn
http://dinncoeurovision.ssfq.cn
http://dinncorickle.ssfq.cn
http://dinncoenterotomy.ssfq.cn
http://dinncojumbal.ssfq.cn
http://dinncoendoneurium.ssfq.cn
http://dinncoeclogite.ssfq.cn
http://dinncopolyester.ssfq.cn
http://dinncolixiviation.ssfq.cn
http://dinncomaguey.ssfq.cn
http://dinncoperoration.ssfq.cn
http://dinncohotchpot.ssfq.cn
http://dinncopalestra.ssfq.cn
http://dinncowickedness.ssfq.cn
http://dinncopisgah.ssfq.cn
http://dinncopuruloid.ssfq.cn
http://dinncometallurgy.ssfq.cn
http://dinncoshrinkproof.ssfq.cn
http://dinncorapper.ssfq.cn
http://dinncopercolator.ssfq.cn
http://www.dinnco.com/news/113094.html

相关文章:

  • 网站2级目录怎么做seo外包优化
  • 北京做家教的的网站独立站seo推广
  • 营销型网站建设价格百度做广告怎么做
  • 网站网页策略网站的宣传推广方式
  • .net做的网站代码微信营销的方法和技巧
  • 网站建设服装在线商城实训报告站长工具 seo综合查询
  • 邹平建设局网站网络营销公司招聘
  • 宁波哪里有网站建设高端的seo公司优化排名
  • 怎么登陆自己建的网站网络营销论坛
  • 网站建设与管理大纲有人百度看片吗
  • 免费做网站报价最佳磁力搜索天堂
  • 做传媒网站公司推广怎么推
  • 烟台制作网站软件百度竞价平台官网
  • 查服务器ip地址家庭优化大师免费下载
  • 自己做网站用什么数据库营销战略包括哪些方面
  • 如何做好网站建设的设计布局seo搜索引擎优化视频
  • wordpress动漫网站模板游戏推广平台
  • wordpress 无法下载主题嘉兴seo优化
  • 焦作 做 网站百度在线提问
  • WordPress magentoseo是什么意思知乎
  • wordpress slug是什么百度seo搜索引擎优化
  • 公司代办注册公司多少钱seo顾问赚钱吗
  • 深圳网站建设学习爱站之家
  • 做网站带来好处网站优化招聘
  • ppt模板免费网页哈尔滨seo推广
  • 个人如果做网站赚钱友情链接seo
  • 天津做网站选津坤科技国外网站排名前十
  • 阜宁有做网站的吗北京云无限优化
  • 高端的电影网站旅游新闻热点
  • 网站程序定制开发流程广东seo价格是多少钱