Skip to content

Slice sum

Go for + range

Flowchart (ISO 5807)

StartInput as = 0x ∈ as = s + xReturn sEndFigure 1 — sum

Source code

Go
func sum(a []int) int {
    s := 0
    for _, x := range a {
        s += x
    }
    return s
}

The editor opens with this code — change it and the chart redraws.

Language
Go
Constructs
for + range
Topic
Loops
Formats
Word, Visio, draw.io, PDF, SVG

Related examples