As you are using post increment it will first check condition and then will perform decrement on that variable so here while(limit--) will be treated as while(limit).
DRY RUN:
var limit = 3;
first time:
while(limit--){ //check limit while limit = 3 returns true and then decrement by 1
console.log(limit); //so now print limit as 2
if(limit){ //check limit while limit = 2
console.log("limit is true"); //so now print this one
}else{
console.log("limit is false")
}
}
second time:
while(limit--){ //check limit while limit = 2 returns true and then decrement by 1
console.log(limit); //so now print limit as 1
if(limit){ //check limit while limit = 1
console.log("limit is true"); //so now print this one
}else{
console.log("limit is false")
}
}
third time:
while(limit--){ //check limit while limit = 1 returns true and then decrement by 1
console.log(limit); //so now print limit as 0
if(limit){ //check limit while limit = 0
console.log("limit is true");
}else{
console.log("limit is false") //so now print this one
}
}
fourth time:
it will not go in while loop as now limit = 0