Question: I want to break out of `.each()` iterations and it doesn't allow me to. Here is my code. Thanks for the help guys! Appreciate it.

```
$('#btn-submit-add').click(function(){
    var answerField = 1;
    $('.addAnswerChoice').each(function(){
        var answerChoice = $(this).val();
        if (answerChoice == ""){
            $('#answerChoice-'+answerField+'-Error').show();
            $(this).focus();
            return false; // this doesn't work
        }
        answerField++;
    });
    alert('doing stuff after');
});

```

Answer: 
My guess is that you're trying to return `false` from the click handler to cancel the submit. The way you have it your `return false` statement returns from the function you passed to `.each()`, which does break out of the `.each()` loop but it doesn't return from the outer function that is the click handler. So execution then continues with the statement after the `.each()`, i.e., the final alert. And your click is not cancelled. Try this instead:

```
$('#btn-submit-add').click(function(e){
    var answerField = 1;
    $('.addAnswerChoice').each(function(){
        var answerChoice = $(this).val();
        if (answerChoice == ""){
            $('#answerChoice-'+answerField+'-Error').show();
            $(this).focus();
            e.preventDefault();
            return false;
        }
        answerField++;
    });
});

```

jQuery passes the [event object](http://api.jquery.com/category/events/event-object/) to your click handler (notice I've added a parameter called `e`), so you can use [`event.preventDefault()`](http://api.jquery.com/event.preventdefault/) to stop the click from working.
From [documentation](http://api.jquery.com/jQuery.each/):

> 
> We can break the $.each() loop at a particular iteration by making the callback function return false. Returning non-false is the same as a continue statement in a for loop; it will skip immediately to the next iteration.
> 
> 
> 

---

Edit:

if @nnnnnn is right, the code should look like:

```
$('#btn-submit-add').click(function(){
    var validated = true;
    var answerField = 1;
    $('.addAnswerChoice').each(function(){
        var answerChoice = $(this).val();
        if (answerChoice == ""){
            $('#answerChoice-'+answerField+'-Error').show();
            $(this).focus();
            validated = false;
            return false;
        }
        answerField++;
    });
    if (!validated)
    {
        return false;
    }
    alert('doing stuff after');
});

```