Skip to content

GCD (Euclid)

PHP while loop

Same task in: PascalGoRust

Flowchart (ISO 5807)

YesNoStartInput a, bb ≠ 0t = bb = a mod ba = tReturn aEndFigure 1 — gcd

Source code

PHP
function gcd($a, $b) {
    while ($b != 0) {
        $t = $b;
        $b = $a % $b;
        $a = $t;
    }
    return $a;
}

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

Language
PHP
Constructs
while loop
Topic
Algorithms
Formats
Word, Visio, draw.io, PDF, SVG

Related examples