Skip to content

Commit c221390

Browse files
shrn01ronreiter
authored andcommitted
Made changes to Hello, World!.md and Variables.md
Added a more detailed explanation of how go code is organised, and fmt package in Hello, World!.md Added details about boolean data type and multiline strings in Variables.md
1 parent ecf5d9f commit c221390

File tree

2 files changed

+65
-1
lines changed

2 files changed

+65
-1
lines changed

tutorials/learn-golang.org/en/Hello, World!.md

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,44 @@
11
Tutorial
22
--------
33

4-
Welcome to the first tutorial. In this tutorial you will learn how to write your first line of code.
4+
Welcome to the first tutorial. This tutorial will guide you through your first go program.
5+
6+
Golang is a modern statistically typed and compiled language from Google.
7+
8+
In each golang program you need to define a package name at the top. So if you need to import your code into some other program you can use this package name to import. Execution of a golang project starts in the package `"main"`. So let's define our package as main.
9+
10+
package main
11+
12+
Go follows a similar pattern as C and has a main function where the execution begins. In go functions are defined using `func` keyword.
13+
14+
This is an example main function
15+
16+
func main () {
17+
18+
}
19+
20+
Now to print something we need to use the Println function from the package `"fmt"`
21+
22+
To import a function you just write import following the package name in "".
23+
24+
import "somemodule"
25+
26+
27+
Here is an example program to print "Hello World!"
28+
29+
package main
30+
31+
import "fmt"
32+
33+
func main () {
34+
fmt.Println("This line is printed")
35+
}
36+
37+
We dont need to add semi colons after each line in Go. The compiler takes care of it.
38+
39+
The `fmt` package also has a `Printf()` function similar to printf in C. It can be used in the same way as it is used in C.
40+
41+
fmt.Printf("%d is a number",10)
542

643
Exercise
744
--------

tutorials/learn-golang.org/en/Variables.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ Tutorial
33

44
A variable is a name given to a storage area that the programs can manipulate. The name of a variable can be composed of letters, digits, and the underscore character. It must begin with either a letter or an underscore.
55

6+
The general code to declare a variable in golang is
7+
8+
var <name of variable> <type of variable>
9+
610
### Numbers
711
Variables are arithmetic types and represent the following values throughout the program.
812
a) integer types
@@ -33,6 +37,21 @@ Single quotes are not used to enable the use of apostrophes in strings without h
3337
var s string = "Don't worry about apostrophes"
3438
fmt.Println(s)
3539

40+
We can also define multiple line strings wrapping the string in `` quotes.
41+
42+
var s string = `This is a string spanning multiple lines
43+
This is the second line
44+
And this is the third`
45+
46+
fmt.Println(s)
47+
48+
### Booleans
49+
Golang supports boolean values with the keywords `true` and `false`
50+
51+
Boolean variables are declared in go as follows
52+
53+
var b bool = true
54+
3655
### Shorthand Declaration
3756
The `:=` notation serves both as a declaration and as initialization.
3857
``` foo := "bar" ``` is equivalent to ``` var foo string = "bar" ```
@@ -44,6 +63,7 @@ The `:=` notation serves both as a declaration and as initialization.
4463
e := "Hello"
4564
f := `Do you like golang, so far?`
4665
g := 'M'
66+
h := true
4767

4868
fmt.Println(a)
4969
fmt.Println(b)
@@ -52,6 +72,7 @@ The `:=` notation serves both as a declaration and as initialization.
5272
fmt.Println(e)
5373
fmt.Println(f)
5474
fmt.Println(g)
75+
fmt.Println(h)
5576

5677

5778

@@ -63,6 +84,7 @@ You must print out to the console the following:
6384
John Doe
6485
24
6586
154.61
87+
true
6688

6789

6890
Tutorial Code
@@ -74,9 +96,11 @@ Tutorial Code
7496
name := "Chris Mien"
7597
age := 29
7698
weight := 200.21
99+
isMale := false
77100
fmt.Println(name)
78101
fmt.Println(age)
79102
fmt.Println(weight)
103+
fmt.Println(isMale)
80104
}
81105

82106

@@ -86,6 +110,7 @@ Expected Output
86110
John Doe
87111
24
88112
154.61
113+
true
89114

90115

91116
Solution
@@ -97,7 +122,9 @@ Solution
97122
name := "John Doe"
98123
age := 24
99124
weight := 154.61
125+
isMale := true
100126
fmt.Println(name)
101127
fmt.Println(age)
102128
fmt.Println(weight)
129+
fmt.Println(isMale)
103130
}

0 commit comments

Comments
 (0)