# Thread: why do all browser lag for this given loop?

1. Registered User
Join Date
Apr 2014
Posts
5

## why do all browser lag for this given loop?

var a,b;
while (a!==b){
if (a>b) {
var a=a-b;
}
else {
var b=b-a;
}
}

so you enter numbers for a and b, and while the condition is true it is doing the given calculations and finally the a and b will became the same and the condition for WHILE will be false and after that it gives out a number a or b (doesnt matter cus both are equal already), also it works for some numbers but browser lags for some specific numbers for example if a=60 and b=120, i dont understand why by the way the given function calculates the largest common divisor of two given numbers, please help me and tell why is it lagging

2. tested your version in ff, works fine. a slightly more improved version
Code:
```var a = 60,
b = 120;

while(a !== b){
if(a > b){
a -= b; // same as "a = a - b"
}else{
b -= a;
}
}

3. Registered User
Join Date
Apr 2014
Posts
5
oh thanks for the improvement I really like it much and for info too that it works for ff but in chrome it still lags i dont use ff