javascript - JS. while loop crashes tab -


i'll go crazy. writing code cyclically gets data server , if use while loop:

var = 100;  while (200>i) {              zz.api("get", {"offset": i, "v": 5.14}, function(data) {          ids = ids.concat(data.response.items.map(maps));         i= + 100;         alert(ids.length);     }); } 

in chrome tab stops responding, firefox crashes.

if use loop

var = 100;  (i=100; i<200; i= i+100) {               zz.api("get", {"offset": i, "v": 5.14}, function(data) {          ids = ids.concat(data.response.items.map(maps));         alert(ids.length);     }); } 

the script executed correctly.

what doing wrong? can not understand, why browser dies "while" looping.

the same result for can done with

var = 100;  while (200>i) {              zz.api("get", {"offset": i, "v": 5.14}, function(data) {          ids = ids.concat(data.response.items.map(maps));         alert(ids.length);     });     i= + 100; } 

in other case, while keeps executing infinitely until async call finished , callback called, loop goes infinite callback never called in javascripts single threaded execution , never gets incremented. meanwhile infinite number of zz.api called resulting in many ajax calls helps in easier crashing.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -