10. To learn it, you gotta 'do' it


#1


#2

Your problem is your while loop is an infinite loop. If you fix the infinite loop you should fix the lesson.


#3

Can you please elaborate how it is an infinite loop?? I am just a beginner who is 12 years old... Please elaborate....


#4

var number= 19;
var getToDaChoppa = function(){
do {
console.log("This is one of my favorite 2 digt number ever....")
}
while(number === 17) {
number= true;
}
};
getToDaChoppa();

// I did this and it worked though can you please explain what was the cause of the infinite loop before this please...tell me...//


#5

Hang on! I am putting my explanation together xD sorry I am the prepare type haha


#6

This was given as an explanation for the purpose of the while loop for this lesson by and it also shows why your infinite loop happen. If you need further explanation just let me know. This answer was given and created by @leonhard.wettengmx.n He has all credit for this answer not me.
What they are trying to achieve,
that you are able to use a while-loop.

         point of entry
         in while-loop
               |
               V

-> while ( condition===true ) -->EXIT--->if condition===false
| { // begin of while-code-block
^
| // your code that will be executed
| // as long as while-condition === true
|
^<- - - } //end of while-code-block,
while-condition is checked again !!
They give you the code:

var understand = true;

while(understand){
console.log("I'm learning while loops!");
//Change the value of 'understand' here!
understand=false; //<<== you make sure
while-condition===false
}
1 You assign true to the variable understand

2 The while-statement -tests the condition-,
--which is the variable understand with its value being true
3 Access is granted to the while-code-block
4 console.log("I'm learning while loops!"); is executed.
5 assignment of the false value to the variable understand
6 END of while-code-block is reached,
goto 2 //The while-statement -tests the condition-, understand

As understand renders to false,
the while will NOT execute its body,
and will EXIT.


#7

Ok.. I get it thanks a lot for your time...


#8

So, as long as the condition is true it executes the statement... Right


#9

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