I have this code, where I would like that next skips to next iteration.
$.each(result, function(key, value) {
if (value.type == "individuel") {
cform["IN"] = "checked";
} else if (value.type == "course") {
cform["CO"] = "checked";
} else {
next;
}
cform["ID"] = key;
cform["title"] = value.title;
$('#template').tmpl(cform).appendTo('#content');
});
But next apparently means something different from what I would expect.
It seams to me that next exits the $.each rather than skipping the current key/value.
Does there exist a way to do next like I would expect?
Due to the nature of jQuery, there is no way to state a “next” in the function body. The inner function does not know that it is being executed in a loop and can therefore not influence this fact.
But you can return early, which has the same effect:
I find this more stylish: