Read "Introducing Go" O ' Reilly, 3rd, 4 chapters

Source: Internet
Author: User
Tags variable scope
This is a creation in Article, where the information may have evolved or changed. The 3rd chapter, variable var x string = "Hello, World" FMT. PRINTLN (x)
var x stringx = "Hello, World" FMT. PRINTLN (x)
var x string = "Hello"
var y string = "world"
Fmt. PRINTLN (x = = y)
Output false
x: = "Hello, ABC" FMT. PRINTLN (x) Short command to create variable or var x = "Hello, World"
var x int = 5

Variable scope scope constant const x string = "Hello, world" constant cannot be changed and then assigned value.
VAR (
A = 5
b = 10
c = 15
)
A multivalued variable that simply simplifies the amount of initialization code. Use the same as a single-valued variable. VAR (
A = 5
b = 10
c = 15
)
Fmt. Println (a)
Fmt. Println (b)
Fmt. Println (c)

If there are variables not using go will error: # command-line-arguments
. \floatcal.go:28:b declared and not used
. \floatcal.go:29:c declared and not used

Small program code: FMT. Print ("Please enter a number:")
var input float64
Fmt. SCANF ("%f", &input)

Output: = input * 2
Fmt. PRINTLN (Output)

The 4th chapter, the control structure FMT. PRINTLN (1)
Fmt. PRINTLN (2)
Fmt. PRINTLN (3)
Fmt. PRINTLN (4)
Fmt. PRINTLN (5)
Fmt. PRINTLN (6)
Fmt. PRINTLN (7)
Fmt. PRINTLN (8)
Fmt. PRINTLN (9)
Fmt. PRINTLN (10)

Fmt. Println (' 1
2
3
4
5
6
7
8
9
10 ')
The same is the multi-line output, note that the latter, the number 2 can not be preceded by a space or tab will be output.
I: = 1for i <= {fmt. PRINTLN (i) i = i + 1} can also be written like this:
For i: = 1; I <= 10; i++ {fmt. Println (i)}
Odd odd, even even if I% 2 = = 0 {fmt. Println (i, "even")} else {fmt. Println (i, "odd")}
Switch I {case 0:fmt. Println ("Zero") default:fmt. Println ("Unknow number")}

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.