Infinite loop on review lesson


#1

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>
https://www.codecademy.com/en/courses/javascript-beginner-en-ASGIv/2/4?curriculum_id=506324b3a7dffd00020bf661

<In what way does your code behave incorrectly? Include ALL error messages.>
My following code generates an infinite loop, I was pretty sure I did everything as told earlier, am I overlooking anything? I believe the problem lies within the “do” syntax as I tested the first two before adding that one, and they seemed to work fine…
The lesson was marked as completed so I could continue but I would really like to know what went wrong here so I won’t make the same mistake again in the future.

```

var forCount = 0;
var forFunction = function(){
for(forCount = 0; forCount < 6; forCount++){
console.log(forCount);
}
}
forFunction();

var whileCount = 0;
var whileFunction = function(){
while(whileCount < 6){
console.log(whileCount);
whileCount++;
}
}
whileFunction();

var doCount = 0;
var doFunction = function(){
do{
console.log(“Gotta do dis thing first doe…”);
} while(doCount){
console.log(doCount);
doCount++;
}
}
doFunction();

<do not remove the three backticks above>

#2

I just realized I forgot to set the while(doCount) to while(doCount < 6), I had this earlier and it still created an infinite loop.


#3

Did you also resolve the issue? I see one here:

do{
        console.log("Gotta do dis thing first doe...");
    } while(doCount){
        console.log(doCount);
        doCount++;
    }

here is some general syntax for a do while loop:

do {
  /* do something */
} while (condition)

here is the general syntax for the while loop:

while (condition){
  /* do something */
}

your while in your do while loop:

while(doCount)

seems to be part of both a do while and while loop, this is impossible.


#4

This fixed my issue thank you!
So like you said the mistake I made was adding the {} after the while in the do while, however the {} after the do take care of this as well.