一、流程控制

Go语言中最常用的流程控制有iffor,而switchgoto主要是为了简化代码、降低重复代码而生的结构,属于扩展类的流程控制。

二、实战

package main

import "fmt"

/**
流程控制及循环遍历
 */
func main() {


	person := [3]string{"tom","zhangsan","jony"}

	fmt.Println("person = ",person)

	// 循环

	for k,v := range  person{

		fmt.Printf("person[%d]:%s\n",k,v)

	}

	fmt.Println("========分割线==========")

	for i :=range person{
		fmt.Printf("person[%d]: %s \n",i,person[i])
	}

	fmt.Println("========分割线==========")

	for i :=0; i< len(person);i++{
		fmt.Printf("person[%d]: %s \n",i,person[i])
	}

	fmt.Println("========分割线==========")

	for _,name := range  person{
		fmt.Println("name =",name)
	}
	
	checkScore()

}

//流程控制if
func checkScore() {
	score := 100
	if score >= 90 {
		fmt.Println("A")
	} else if score > 75 {
		fmt.Println("B")
	} else {
		fmt.Println("C")
	}
}


// switch 流程控制
func switchType() {
	finger := 3
	switch finger {
	case 1:
		fmt.Println("幼儿园")
	case 2:
		fmt.Println("小学")
	case 3:
		fmt.Println("中学")
	case 4:
		fmt.Println("大学")
	case 5:
		fmt.Println("家里蹲")
	default:
		fmt.Println("打工人")
	}