简体   繁体   中英

Why does this loop never ends?

I dont understand why this wont just give me 1 alert instead of infinite alerts.

var x=1;

$(document).ready(function(){
  do{
     alert("hey");
     x--;
  }while(x=1);
});

Inside while x=1 is not a condition. It is a assignment. Try x==1. Then it will work

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM