(function(players) {
var cur_idx = 0;
function cb(name, err) {
// just kidding, not going to handle errors!
if (IsValidName(name)) {
players[cur_idx].name = name;
cur_idx++;
}
if (cur_idx < players.length) {
Ask("What's your name", cb);
}
}
Ask("What's your name", cb);
})(players);
This is of course completely awful. just2n's reply is a nicer realization of the same concept. sprobertson's reply clearly will not work as written, and I don't expect it's even possible to condense this code into a single call to eachSeries.