Skip to content

Commit 3a27414

Browse files
ʇɹǝqƃǝᴉs puɐloɹquii
ʇɹǝqƃǝᴉs puɐloɹ
authored andcommitted
Explain usage of var (quii#224)
* Explain usage of `var` As `:=` has been used so far, it is explained briefly with a reference to examples. * Simplify explanation and add reflection reference
1 parent a5c02e4 commit 3a27414

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

iteration.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,13 @@ func Repeat(character string) string {
6161
}
6262
```
6363

64-
Unlike other languages like C, Java, or JavaScript there are no parentheses surrounding the three components of the for statement and the braces { } are always required.
64+
Unlike other languages like C, Java, or JavaScript there are no parentheses surrounding the three components of the for statement and the braces { } are always required. You might wonder what is happening in the row
65+
66+
```go
67+
var repeated string
68+
```
69+
70+
as we've been using `:=` so far to declare and initializing variables. However, `:=` is simply [short hand for both steps](https://gobyexample.com/variables). Here we are declaring a `string` variable only. Hence, the explicit version. We can also use `var` to declare functions, as we'll see later on.
6571

6672
Run the test and it should pass.
6773

0 commit comments

Comments
 (0)