Exit For in C#?
-
What's the 'Exit For' equivalent in C#?
-
What's the 'Exit For' equivalent in C#?
break
? -
break
?thx
-
thx
Most times when you use this it indicates that you have used the wrong construct. If you are issuing a break then this shows that you have reached a terminating condition. If you need to drop out of a loop early, this would indicate that you should be using something like a while loop instead. See the following:
for (int i = 0; i < 10 ; i++) { // Do something if (i == 2) break; }
Contrast this with:
int i = 0; while (i++ != 2) { // Do something }
the last thing I want to see is some pasty-faced geek with skin so pale that it's almost translucent trying to bump parts with a partner - John Simmons / outlaw programmer
Deja View - the feeling that you've seen this post before. -
Most times when you use this it indicates that you have used the wrong construct. If you are issuing a break then this shows that you have reached a terminating condition. If you need to drop out of a loop early, this would indicate that you should be using something like a while loop instead. See the following:
for (int i = 0; i < 10 ; i++) { // Do something if (i == 2) break; }
Contrast this with:
int i = 0; while (i++ != 2) { // Do something }
the last thing I want to see is some pasty-faced geek with skin so pale that it's almost translucent trying to bump parts with a partner - John Simmons / outlaw programmer
Deja View - the feeling that you've seen this post before.Pete O'Hanlon wrote:
If you need to drop out of a loop early, this would indicate that you should be using something like a while loop instead.
Or a different for expression
Node n = null;
NodeList list = doc.selectNodes("*");
for(int j=0, null == n && j < list.Length, j++)
{
if( ???)
n = list[j];
}led mike
-
Most times when you use this it indicates that you have used the wrong construct. If you are issuing a break then this shows that you have reached a terminating condition. If you need to drop out of a loop early, this would indicate that you should be using something like a while loop instead. See the following:
for (int i = 0; i < 10 ; i++) { // Do something if (i == 2) break; }
Contrast this with:
int i = 0; while (i++ != 2) { // Do something }
the last thing I want to see is some pasty-faced geek with skin so pale that it's almost translucent trying to bump parts with a partner - John Simmons / outlaw programmer
Deja View - the feeling that you've seen this post before.Ya, Ya, we all know the theory; but break is more handier
-
Ya, Ya, we all know the theory; but break is more handier
Handy doesn't make it right. Just lazy. If you take shortcuts here, where else do you take shortcuts? Whenever I see something like this, it sets the alarm bells ringing that there are problems with the design.
the last thing I want to see is some pasty-faced geek with skin so pale that it's almost translucent trying to bump parts with a partner - John Simmons / outlaw programmer
Deja View - the feeling that you've seen this post before. -
Ya, Ya, we all know the theory; but break is more handier
And if it's due to an exceptional state, it may be more expressive. But certainly use it with caution.