i cant understand the code

this code finds the gcd of two numbers i cant understand how it works.
first you get the remainder of the bigger number by the smaller number and then
set the remainder to the variable of the last big number and then repeat the whole procces again until the remainder of the bigger number is 0 by the smaller number i cant understand it can somebody explain?

1
2
3
4
5
6
7
8
9
10
11
12
  public static void main(String[] args)
{
int x=10,y=136,gcd=0,dup;
for(;gcd==0;)
{
if(x%y==0)
gcd=y;
dup=y;
y=x%y;
x=dup;
	
}	
Looks like: http://en.wikipedia.org/wiki/Euclidean_algorithm


PS. Style, including indentation, does affect the clarity of the code and can prevent some typographical errors too:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
int x =  10;
int y = 136;

int gcd = 0;
while ( 0 == gcd )
{
  if ( 0 == x%y )
  {
    gcd = y;
    // could break here
  }

  const int temp = y;
  y = x % y;
  x = temp;
}
Topic archived. No new replies allowed.