Documentation
Golang 101
0 - Ultimate Gopherlabs
1 - Lets Start With First Hello world Program
2 - Numeral Systems - Decimal
3 - Numeral Systems - Binary
4 - Numeral systems - hexadecimal
5 - Numeral Systems - Loop
6 - Numeral Systems UTF-8
7 - Short variable declarations
8 - Variable with zero value
9 - Deep Drive on Variables
10 - Deep Drive On Constants
11 - Loop Init, Condition, Post
12 - Loop - Nested Loops
13 - Loop - For Statement
14 - Loop - Break & Continue
15 - Generate Random number with math/crypto/rand in Go
16 - Loop - Printing ASCII
17 - Conditional - If Statement
18 - Conditional - If, Else if, Else
19 - Loop, Conditional, Modulus
20 - Conditional - Switch Statement
21 - Conditional - Switch Statement Documentation
22 - Conditional Logic Operators
23 - String Type
24 - Bool Type
25 - Structs
26 - Struct Literal
27 - Pointer to struct
28 - Conversion, Not Casting
29 - Creating Your Own Type
30 - Defer
31 - Stacking defers
32 - Pointer
33 - Prefix Suffix
34 - Conversion between array and slice
35 - methods
36 - variadic function
37 - init Function
38 - Command Line Arguments and File I/O
39 - what is interface ?
40 - Retrieving the Golang version
41 - accessing program arguments
42 - Creating a program interface with the flag package
43 - Retrieving the current working directory
44 - Getting the current process PID
45 - Handling operating system signals
46 - calling an external proces
47 - Retrieving child process information
48 - Reading writing from the child process
49 - Shutting down the application gracefully
50 - file configuration with functional options
51 - Finding the substring in a string
52 - breaking the string into words
53 - Joining the string slice with a separator
54 - Concatenating a string with writer
55 - Aligning text with tabwriter
56 - Replacing part of the string
57 - finding the substring in text by the regex pattern
58 - controlling case
59 - parsing comma-separated data
60 - managing whitespace in a string
61 - indenting a text document
62 - converting strings to numbers
63 - comparing floating-point numbers
64 - rounding floating-point numbers
65 - floating-point arithmetics
66 - formatting numbers
67 - Converting between binary, octal, decimal, and hexadecimal
68 - formatting with the correct plurals
69 - generating random numbers
70 - operating complex numbers
71 - converting between degrees and radians
72 - taking logarithms
73 - generating checksums
74 - reading standard input
75 - Writing standard output and error
76 - opening a file by name
77 - reading the file into a string
78 - Reading writing a different charset
79 - Seeking a position within a file
80 - reading and writing binary data
81 - writing to multiple writers at once
82 - piping between writer and reader
83 - serializing objects to binary format
84 - reading and writing ZIP files
85 - Parsing a large XML file effectively
86 - extracting data from an incomplete JSON array
87 - getting file information
88 - creating temporary files
89 - writing the file
90 - writing the file from multiple goroutines
91 - listing a directory
92 - Changing file permissions
93 - Creating files and directories
94 - Filtering file listings
95 - comparing two files
96 - Resolving the user home directory
Loop Init, Condition, Post
As you’re learning Go, a good quick reference is Go by Example.
For example, here’s what it has for for
package main
import "fmt"
func main() {
i := 1
for i <= 3 {
fmt.Println(i)
i = i + 1
}
for j := 7; j <= 9; j++ {
fmt.Println(j)
}
for n := 0; n <= 5; n++ {
if n%2 == 0 {
continue
}
fmt.Println(n)
}
}
Note: There is no while in Go.
The way to create a loop is to start with for, and the first thing you put in is an init statement, a condition, and a post, e.g.
for init; condition; post {
}
Let’s try a loop with an init statment initializing a variable i with the value 0, the condition that i is less than or equal to 100, and the post of incrementing i by 1 (i++). Remember, we can always check the Go spec. In this case, IncDec statements has information explaining the ++ and -- operators.
package main
import (
"fmt"
)
func main() {
// for init; condition; post {}
for i := 0; i <= 100; i++ {
fmt.Println(i)
}
}