While Loop Basic Q


#1

https://www.codecademy.com/en/courses/javascript-beginner-en-ASGIv/1/2?curriculum_id=506324b3a7dffd00020bf661


This is probably a simple question but any help is great! :blush: Under console.log what exactly does the variable = false do? I know you need it so you don't get trapped in an infinite loop but what does it do? if that makes any sense at all.


var i = true;

var soloLoop = function(){
  while (i === true) {  
    console.log("Looped once!");
    i = false;
  }
};

soloLoop();


#2

it updates the variable i and gives it a value of false, so then when in the next run of the loop the condition is checked, it evaluates to false, the loop ends


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.