When to "while and "for" loops?


#1

am I on the right track?

var loup = 0;

var loop = function(){
    for (loup = 0;loup < 5;loup++){
        console.log("let's do this!");
    }   
    else{
        console.log("stop!, next!");
    
    }
    while (loup < 7){
        console.log("made it!");
            loup++;
            }
};

#2

Mostly, only the else part is really wrong. Else is the default case for an if statement so it can't be without it (if).
The other things are less errors but more things that you should consider. One question is why you declare you're loup variable outside of the function when you directly reinitialize it inside the function as well? Why not just add a var to loup =0 inside of the for loop instead of making it global when it is not used there? Also loop and loup look pretty similar almost got confused by this :slightly_smiling: . And last but the while loop: It is not wrong but are you aware of the fact that both loops use the same variable and therefore you're while doesn't start at 0 but at 5 because that is value of loup where the for loop stops? As said it is not wrong but it creates an unnecessary complexity and so it would be better to use a different counting variable for each loop.