Fundamentals5 / 10
Up next

for is the only loop

package main

import "fmt"

func main() {
	// classic three-part for
	sum := 0
	for i := 1; i <= 5; i++ {
		sum += i
	}
	// for with only a condition works like while
	n := 1
	for n < 100 {
		n *= 2
	}
	fmt.Println(sum, n)
}
What you're solving

three-part form and while form