1
Good morning, I’m starting on nodejs. I need to get one function that is called inside the other back into my loop, but I’m having a hard time with that. Follow below the code I made. From loop to teste2 and teste2 to teste3 and teste3 rec
var teste3 = function teste3(n){
if (n == 2 || n == 4) {
console.log("chego na 3")
return;
};
}
var teste2 = function teste2(n, callback){
if (n == 1 || n == 5) {
console.log("chego no 2")
}else if (n == 2 || n == 4){
callback(n);
}
}
var i = 0;
var teste = function teste(){
while(i < 10){
teste2(i, teste3);
console.log(i);
i++
}
}
teste();
What’s the problem? This code seems to be working normally.
– bfavaretto
The goal is to stop the loop if you enter the
if
ofteste3
?– bfavaretto
My goal is to go back to the loop and continue it, this question was just an example, if you had another if in test3 not to make var test3 = Function teste3(n){ if (n == 2 || n == 4) { //return to the loop without doing the next if console.log("I arrive at 3") Return; }; if(n == 0){ } }
– Fortunato