When to 'while' and when to 'for' - not logging to console?


#1

I have the following code and it checks out/allows me to "Go To Next Lesson", but it doesn't log anything to the console. If I remove the For statement, or the While statement, it logs something. But when I put them together as below, it doesn't. I'm perplexed.

var i = 0

var print = function(){
for (i = 0; i >= 10; i++){
while (i < 3){
console.log(i + " is less than 3");
}
while (i > 3){
console.log(i + " is more than 3");
}

}
}

print();


#2

shouldn't you better write : for i <= 10 ?


#3

Also be careful with your while loops. These things loop while the condition is true and only stop if the condition is false so you need to make sure that it becomes false after it did what it was supposed to do:

while (i < 3){
    console.log(i + " is less than 3");
    }
    while (i > 3){
    console.log(i + " is more than 3");
    }

these loops don't change the value of i inside, so if they're true once you're trapped in an infinite loop.