Skip to content

foreach

C# foreach over a collection

Flowchart (ISO 5807)

StartInput as = 0x ∈ as = s + xReturn sEndFigure 1 — P.Sum

Source code

C#
class P {
    static int Sum(int[] a) {
        int s = 0;
        foreach (var x in a) {
            s += x;
        }
        return s;
    }
}

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

Language
C#
Constructs
foreach over a collection
Topic
Loops
Formats
Word, Visio, draw.io, PDF, SVG

Related examples