I’m in a need to do a certain algorithm but I'm having a problem with For loops. The first problem is that I can't make the execution of two For loops (one inside the other) without the first ends and doesn't wait for the second one to finish
for(i = ports_default; i <= ports_final; i++) {
for(j=ports_default; j<= (ports_default + num_ports) ;j++){
client.portUnmapping({public: j},function (err){
if (err) {
callback(err);
}
else {
console.log('Port ' + ports_default + ' unmapped');
ports_default= ports_default + 1;
if(ports_default == j) {
callback();
}
}
});
}
ports_default = ports_default + num_ports + 1;
}
I've tried the async module but couldn't find a proper solution for this problem, the second problem is that node won't wait for a response from the portUnmapping function, my question is if theres a way to atleast force it somehow to wait for both For loops to end (in the proper order not finishing the first one and then the second one).