Click here to Skip to main content
15,890,506 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: Loop exit Pin
Mark_Wallace30-Jul-14 19:38
Mark_Wallace30-Jul-14 19:38 
GeneralRe: Loop exit Pin
Simon O'Riordan from UK30-Jul-14 22:00
Simon O'Riordan from UK30-Jul-14 22:00 
GeneralRe: Loop exit Pin
Pablo Aliskevicius30-Jul-14 1:35
Pablo Aliskevicius30-Jul-14 1:35 
GeneralRe: Loop exit Pin
kalberts30-Jul-14 2:08
kalberts30-Jul-14 2:08 
GeneralRe: Loop exit Pin
Dan Neely30-Jul-14 2:26
Dan Neely30-Jul-14 2:26 
GeneralRe: Loop exit Pin
irneb30-Jul-14 20:04
irneb30-Jul-14 20:04 
GeneralRe: Loop exit Pin
Stefan_Lang30-Jul-14 20:11
Stefan_Lang30-Jul-14 20:11 
GeneralRe: Loop exit Pin
harvyk030-Jul-14 20:28
harvyk030-Jul-14 20:28 
Here is a real world example for you

C#
for (property = 0, len = obj.length; property < len; property++) {
    if (callback.call(obj[property], property, obj[property]) === false) {
        break;
    }
}


Once the following is true (callback.call(obj[property], property, obj[property]) === false), there is no point in continuing the loop, as a result the break will exit the loop.

If the method has the answer it is looking for, you can also do

C#
for (property = 0, len = obj.length; property &lt; len; property++) {
    if (callback.call(obj[property], property, obj[property]) === false) {
        return 1;
    }
}


so that not only will the loop end, but if there is nothing more in the method which will add value to the answer, the data is returned without needing to continue (bad choice of words, since continue has it's own special meaning) the loop and without needing to look at any more code.
GeneralRe: Loop exit Pin
Stefan_Lang30-Jul-14 20:39
Stefan_Lang30-Jul-14 20:39 
AnswerRe: Loop exit Pin
L. Braun31-Jul-14 0:10
L. Braun31-Jul-14 0:10 
GeneralRe: Loop exit Pin
Mark_Wallace31-Jul-14 0:17
Mark_Wallace31-Jul-14 0:17 
GeneralRe: Loop exit Pin
Mark_Wallace31-Jul-14 0:18
Mark_Wallace31-Jul-14 0:18 
GeneralRe: Loop exit Pin
Stefan_Lang31-Jul-14 0:34
Stefan_Lang31-Jul-14 0:34 
GeneralRe: Loop exit Pin
L. Braun31-Jul-14 1:40
L. Braun31-Jul-14 1:40 
GeneralRe: Loop exit Pin
Stefan_Lang31-Jul-14 3:24
Stefan_Lang31-Jul-14 3:24 
GeneralRe: Loop exit Pin
kalberts31-Jul-14 23:33
kalberts31-Jul-14 23:33 
GeneralRe: Loop exit Pin
Stefan_Lang3-Aug-14 23:50
Stefan_Lang3-Aug-14 23:50 
GeneralRe: Loop exit Pin
Eduard Matei31-Jul-14 0:59
Eduard Matei31-Jul-14 0:59 
GeneralRe: Loop exit Pin
Matthew Barnett31-Jul-14 1:20
Matthew Barnett31-Jul-14 1:20 
GeneralRe: Loop exit Pin
kalberts31-Jul-14 23:11
kalberts31-Jul-14 23:11 
GeneralRe: Loop exit Pin
M. Eugene Andrews31-Jul-14 1:53
M. Eugene Andrews31-Jul-14 1:53 
GeneralRe: Loop exit Pin
crazedDotNetDev31-Jul-14 5:59
crazedDotNetDev31-Jul-14 5:59 
GeneralRe: Loop exit Pin
kalberts31-Jul-14 22:58
kalberts31-Jul-14 22:58 
GeneralRe: Loop exit Pin
crazedDotNetDev1-Aug-14 10:34
crazedDotNetDev1-Aug-14 10:34 
GeneralRe: Loop exit Pin
Member 460889831-Jul-14 5:58
Member 460889831-Jul-14 5:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.