Practice: Fibonacci
Generate numbers with a loop and multiple assignment.
Example
package main
import "fmt"
func main() {
a, b := 0, 1
for i := 0; i < 10; i++ {
fmt.Print(a, " ")
a, b = b, a+b
}
fmt.Println()
}Result
0 1 1 2 3 5 8 13 21 34
Exercise
Swap in one line.
a, b = b, ab
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.