Skip to content

for-each

Java for (T x : c)

Flowchart (ISO 5807)

YesNoStartInput a, keyc = 0x ∈ ax = keyc = c + 1Return cEndFigure 1 — P.count

Source code

Java
class P {
    static int count(int[] a, int key) {
        int c = 0;
        for (int x : a) {
            if (x == key) c++;
        }
        return c;
    }
}

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

Language
Java
Constructs
for (T x : c)
Topic
Loops
Formats
Word, Visio, draw.io, PDF, SVG

Related examples