Go language study essay 2019-10-30

Go language study essay 2019-10-30

1. Conditional statements

1)if

if a > 10{
    //do something
}

2)if-else

if a > 10{
    //do something
} else{
    //do other things
}

Notice

else statements should be on the same line as the if statement’s ‘}’,otherwise an error will be reported.

3)nested if

if a > 10{
    //do something
    if b < 10{
        //do something
    }
}

4)switch

switch a{
    case 1:
      ...
    case 2:
      ...
    default:
      ...
}
Notice

You don’t need to write break statement after case statement.
If you want to continue excute the code which behind matched case statements,please use fallthrough.

5)select

Select statement is like switch statement,but the different is that switch statement’s every case statement is a channel operation.Otherwise,select statement hasn’t conditional experession,his excution is random,for example:

var c1,c2 chan int
var a,b int 
switch{
    case c1 <- a:
        //send
    case b = <-c2:
        //receive
    default:
        //blabla...
}
Notice

Go doesn’t have trinocular operator,so it doesn’t support the conditional judgment of the ?: form.

2.Loop statement

1)for loop

for i :=0; i < 10; i++{
    //do someting
}

for a < b{
    //do someting
}

for index,item := range numbers{
    //do someting
}

2)nested loop

for i :=0; i < 10; i++{
    for j :=i; j < 10; j++{
        //do something
    }
}

3)break,continue,goto

  • break
for i :=0; i < 10; i++{
    if a>5 {
        // if a>5 ,stop loop
        break
    }
}
  • continue
for i :=0; i < 10; i++{
    if a == 5 {
        // skip this loop 
        i++
        continue
    }
}
  • goto
LOOP: fmt.Println("lalala")
for i :=0; i < 10; i++{
    if a == 5 {
        // stop loop and jump to line 1
        goto LOOP
    }
}
Notice

forever loop:

for true{
    //I love you
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
很抱歉,您要求的内容需要用英文进行回答。 以下是一篇生物传记散文,长度约为200-300字: Born in a small town in the countryside, Jane Doe grew up surrounded by nature and animals. She developed a love for the outdoors and a deep appreciation for the natural world at a young age. Her parents, both teachers, encouraged her interests and provided her with the resources she needed to pursue her passions. As Jane grew older, her love for the environment only grew stronger. She studied environmental science in college and went on to earn a master's degree in ecology. Throughout her academic career, Jane worked tirelessly to learn as much as she could about the world around her and to find ways to protect it. After graduation, Jane took a job with a local non-profit organization that focused on preserving wildlife habitats. She spent years working on the ground, conducting research, and advocating for the protection of endangered species. Her work took her all over the world, from the rainforests of South America to the savannas of Africa. Despite the challenges she faced, Jane never lost sight of her goals. Her tireless efforts and unwavering dedication to the cause earned her recognition and respect within the environmental community. She became a respected voice on environmental issues and an inspiring leader for those who shared her passion for preserving the natural world. Today, Jane continues to work tirelessly to protect the environment and raise awareness about the importance of conservation. Her life's work serves as a testament to the power of one person to make a difference and her legacy will live on for generations to come.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值