Golang Process Control if statement

Source: Internet
Author: User

1. If Else statement

Basic syntax

Single condition judgment if condition {    //do something}//multi-condition judgment if condition {} else if condition {    //do something} else {//do    so Mething}

If single condition followed by a statement and then made conditional judgment

If statement;condition{    //do something}//single condition, without the basic judgment of the statement package Mainimport ("FMT") func main () {nu: = 1if nu%2 = = 0 {fmt. Println ("The number is even")} else{fmt. Println ("The number is odd")}}//single condition, with statement of Judgment package Mainimport ("FMT") func main () {   if nu: = +; Nu% 2 = = 0 {//with an assignment statement After doing the judging   fmt. Println ("The number is even")   } else{   fmt. Println ("The number is odd")   }}

Note: It is not very build justice to do this because logic looks complicated, but it can reduce the amount of code

If multi-criteria followed by a statement and then made conditional judgment

Multi-condition, without statement of Judgment package Mainimport ("FMT") func main () {num: = 34if num <= 50{fmt. Println ("number is not then")} else if num >= && num <= 100{fmt. Println ("The number is between And1")} else{fmt. Println ("The number is greater than 100")}}//multi-criteria, with Statement of Judgment package Mainimport ("FMT") func main () {//num: = 34if num: = 78;num &L T;= 50{fmt. Println ("number is not then")} else if num >= && num <= 100{fmt. Println ("The number is between And1")} else{fmt. Println ("The number is greater than 100")}}

  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.