### Statements in if
```go
-if _, err := getResult(); err != nil {
+if _, err := doThing(); err != nil {
fmt.Println("Uh oh")
}
```
{: data-line="1"}
-A condition in an `if` statement can be preceded with a statement before a `;`.
+A condition in an `if` statement can be preceded with a statement before a `;`. Variables declared by the statement are only in scope until the end of the `if`.
See: [If with a short statement](https://tour.golang.org/flowcontrol/6)
See: [For-Range loops](https://gobyexample.com/range)
+### While loop
+
+```go
+n := 0
+x := 42
+for n != x {
+ n := guess()
+}
+```
+
+See: [Go's "while"](https://tour.golang.org/flowcontrol/3)
+
## Functions
{: .-three-column}
See: [Pointer receivers](https://tour.golang.org/methods/4)
+## Interfaces
+
+### A basic interface
+
+```go
+type Shape interface {
+ Area() float64
+ Perimeter() float64
+}
+```
+
+### Struct
+
+```go
+type Rectangle struct {
+ Length, Width float64
+}
+```
+
+Struct `Rectangle` implicitly implements interface `Shape` by implementing all of its methods.
+
+### Methods
+
+```go
+func (r Rectangle) Area() float64 {
+ return r.Length * r.Width
+}
+
+func (r Rectangle) Perimeter() float64 {
+ return 2 * (r.Length + r.Width)
+}
+```
+
+The methods defined in `Shape` are implemented in `Rectangle`.
+
+### Interface example
+
+```go
+func main() {
+ var r Shape = Rectangle{Length: 3, Width: 4}
+ fmt.Printf("Type of r: %T, Area: %v, Perimeter: %v.", r, r.Area(), r.Perimeter())
+}
+```
+
## References
### Official resources