javascript - Simple js loop using null as a condition -
/i trying make simple loop. can't seem work.
var c =0; while (x !== false) { x = men[c].plat; if (x == "null") {break;} f = f + x + "<br>"; c++; } var men = [ {"plat": 7}, {"plat": 1}, {"plat": null }];
i want loop see "null" string , leave loop. thanks
assuming else fine, check should x === null
since null
keyword, not string. also, declaration of men
needs before loop, or else that's not accessible.
tip: huge favor , pick more descriptive variable names. rule of thumb never use 1-character variable names aren't loop counters.
Comments
Post a Comment