Go language conditional statement if else

Source: Internet
Author: User

Example:

If a < 5 {     return 0} else {     return 1}  

For conditional statements, the following points need to be noted:
? Conditional statements do not need parentheses to enclose conditions ();
? The curly braces {} must exist regardless of the statement body.
? The left curly brace {must be in the same row as if or else;
? After the IF, the conditional statement can be added before the variable initialization statement, use; interval;
? In a function that has a return value, the "final" return statement is not allowed to be included in the If...else ... Structure, otherwise the compilation fails:


The reason for the failure is that the go compiler cannot find the return statement that terminates the function. The following are examples of failed compilations:

func example (x int) int {if x = = 0 {return 5} else {return x}}

  

Go language conditional statement if else

Related Article

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.