Skip to content

Commit 04a5d47

Browse files
committed
variables explained
1 parent 2d52974 commit 04a5d47

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

var.go

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// variable scope
2+
// In golang scope is defined as block. A block is a possibly empty sequence of declaration and statements within matching curly bracke
3+
// In golang there are two types of block inner block and outer block
4+
// Inner block can access the variables that are declared in the outer block
5+
// Outer block cannot access the variables that are declared in the inner block.
6+
package main
7+
8+
import "fmt"
9+
10+
func main() {
11+
city := "London"
12+
{
13+
country := "UK"
14+
fmt.Println(city)
15+
fmt.Println(country)
16+
}
17+
fmt.Println(city)
18+
}

0 commit comments

Comments
 (0)