Infinite Loop! Can someone take a look at my "To learn it, you gotta do it"


#1

Continuing the discussion from 10. To learn it, you gotta 'do' it:

var condition=1;
var getToDaChoppa = function(){
// Write your do/while loop here!
do {
console.log("I'm tired of looping for a while.");
} while(condition);
count++;
condition=false;
};

getToDaChoppa();


#2

This variable is not defined, and not needed.

This line should be moved to just inside the do { // in here } while();.


#3

Omg! It worked. Thank you. So appreciated.
I knew I was close. I didn't think I needed the count++ and suspected it was creating the infinite loop.
Am I correct in my understanding why I needed to move condition=false; to under the do portion of the loop versus the while part of it. I think it is because do means to do it at once so I need to address the false condition first rather than waiting. Is that right? I want to be sure I understand.

Thank you!! - Dany


#4

The term 'under' is a bit misleading. We're actually moving it inside the code body of the do {} block. This is the control used in the break condition as stipulated by the while() expression.

It is important to have the control inside the loop, else the condition will never change. That is what caused the infinite loop (not count++.


#5

Ahh!! Thank you and for the clarification on the proper way to express it (control versus my misleading use of under).
It does make sense and I am more clear on what caused the infinite loop.
Appreciate you!