5

3.golang流程控制

 3 years ago
source link: https://studygolang.com/articles/32382
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

3.golang流程控制

haodevops · 大约21小时之前 · 76 次点击 · 预计阅读时间 1 分钟 · 不到1分钟之前 开始浏览    

1、递增递减

f5bd76f58478b929328f1ec6ea027a8a.png

package main

import "fmt"

func main(){

fmt.Println(a)

fmt.Println(a)

2、条件语句

9c18f5936530d5550f7901f11ef75863.png

package main

import "fmt"

func main(){

  if (a >3) {

fmt.Println("进去正确判断")

}else {

fmt.Println("进去错误判断")

3、选择语句

69867f08dd66a04d5b312b5d39ecbbe2.png

package main

import "fmt"

func main(){

  switch a {

case 0:

fmt.Println("0")

case 1:

fmt.Println("1")

fallthrough //进入下一个case

  case 2:

fmt.Println("2")

default:

fmt.Println("都不成立")

4、循环语句

package main

func main(){

fmt.Println(a)

      if (a>10) { //可以加括号也可以不加break

  for (a<10){  //可以加括号也可以不加a++

fmt.Println(a)

for a:=0;a<10;a++{

fmt.Println(a)

5、跳转语句

package main

import "fmt"

func main(){

  for a<10{

if(a==5){

continue //跳出5这次循环

fmt.Println(a)

291cca19972fc3cc3e8b0369983327ef.png

package main

import "fmt"

func main(){

for a<10{

if(a==5){

break A

goto B

fmt.Println(a)

fmt.Println("我来到B了")


有疑问加站长微信联系(非本文作者)

280

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK