3.golang流程控制
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.
3.golang流程控制
haodevops · 大约21小时之前 · 76 次点击 · 预计阅读时间 1 分钟 · 不到1分钟之前 开始浏览1、递增递减
package main
import "fmt"
func main(){
fmt.Println(a)
fmt.Println(a)
2、条件语句
package main
import "fmt"
func main(){
if (a >3) {
fmt.Println("进去正确判断")
}else {
fmt.Println("进去错误判断")
3、选择语句
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)
package main
import "fmt"
func main(){
for a<10{
if(a==5){
break A
goto B
fmt.Println(a)
fmt.Println("我来到B了")
有疑问加站长微信联系(非本文作者)
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK