javascript - While loop multiple conditions don't check both conditions -


var x = 0; var y = 0;  while (x < 10 && y < 20){   x += 1;   y += 1;   console.log('this x: ', x)   console.log('this y: ', y) } 

i don't think understand how multiple conditions in loops work. expect code continue loop until x greater 10 , y greater 20 loop stops once x greater 10. thought && means both conditions have met.

i thought && means both conditions have met

it does. x no longer less 10, condition isn't met. want or, either condition has met:

while (x < 10 || y < 20){ 

though in simple case, loop controlled y variable anyway they're incremented @ same rate.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -