How to improve my codes to implement 'return false'?
<p>I am trying to return false after a conditional statement fail.</p>

<p>I have</p>

<pre><code>$('#btn').click(function() {
    $('.title').each(function() {
        if (id == $(this).attr('id')) {
            alert('The name already exists.')
            return false; //I hope my codes would stop here if condition is true
        }
    })
    // my codes still call the doSomething function even if the conditional         
    //statement is true
    doSomething();
})​
</code></pre>

<p>I want do call the <code>doSomething</code> function ONLY if <code>id != $(this).attr('id).</code> </p>

<p>The codes below gave me what I want but it seems ugly.  </p>

<pre><code>$('#btn').click(function() {
    var nameExist = false
    $('.title').each(function() {
        if (id == $(this).attr('id')) {
            alert('The name already exists.')
            nameExist = true;
            return false; //I hope my codes would stop here if condition is true
        }
    })
    if (!nameExist) {
        doSomething();
    }
})​
</code></pre>

<p>Anyone has a better approach for this? Thanks a lot!</p>
