By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,364 Members | 1,267 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,364 IT Pros & Developers. It's quick & easy.

How do I jump to the Next row in a foreach

P: n/a
C#

I am iterating through a collection of rows thus:

foreach(DataRow myRow in dsTable.Table[0].Rows)
{
...........
}

in this loop I have some conditions and when one is met I dont want it to
procede down the code, I want it to go back to the top of the loop and
process the next row in the collection. How do I do this?

In a previous life when programming with Progress you could do this:

myloop:
FOR EACH row:

IF myconditionismet THEN
NEXT myloop

.........

END.

This is the kind of thing I am after.

Thanks

Steve
Feb 9 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
"continue"

"Steve" <St***@discussions.microsoft.com> wrote in message
news:F8**********************************@microsof t.com...
C#

I am iterating through a collection of rows thus:

foreach(DataRow myRow in dsTable.Table[0].Rows)
{
..........
}

in this loop I have some conditions and when one is met I dont want it to
procede down the code, I want it to go back to the top of the loop and
process the next row in the collection. How do I do this?

In a previous life when programming with Progress you could do this:

myloop:
FOR EACH row:

IF myconditionismet THEN
NEXT myloop

........

END.

This is the kind of thing I am after.

Thanks

Steve

Feb 9 '06 #2

P: n/a

I would just put the optional code in an if() statement block.
foreach ()

{

Do();

Do2();
Do3();

if(x)
{
do4();
do5();

}

}
Steve wrote:
C#

I am iterating through a collection of rows thus:

foreach(DataRow myRow in dsTable.Table[0].Rows)
{
..........
}

in this loop I have some conditions and when one is met I dont want it to
procede down the code, I want it to go back to the top of the loop and
process the next row in the collection. How do I do this?

In a previous life when programming with Progress you could do this:

myloop:
FOR EACH row:

IF myconditionismet THEN
NEXT myloop

........

END.

This is the kind of thing I am after.

Thanks

Steve

Feb 9 '06 #3

P: n/a

If I put that in a case statement condition -- would I have to also use
break; ?

or would it be

continue;
break;


Peter Rilling wrote:
"continue"

"Steve" <St***@discussions.microsoft.com> wrote in message
news:F8**********************************@microsof t.com...
C#

I am iterating through a collection of rows thus:

foreach(DataRow myRow in dsTable.Table[0].Rows)
{
..........
}

in this loop I have some conditions and when one is met I dont want it to
procede down the code, I want it to go back to the top of the loop and
process the next row in the collection. How do I do this?

In a previous life when programming with Progress you could do this:

myloop:
FOR EACH row:

IF myconditionismet THEN
NEXT myloop

........

END.

This is the kind of thing I am after.

Thanks

Steve


Feb 9 '06 #4

P: n/a
The continue statement passes control to the next iteration of the enclosing
iteration statement in which it appears.

The switch has the following form:

switch (expression)
{
case <constant-expression>:
<statement>
<jump-statement>
[default:
<statement>
<jump-statement>]
}

A jump statement that transfers control out of the case body and may be
break, continue, default, goto or return

So no break after continue;

I hope that helps.

Regards,
Arnd Hurlbrink
"John Bailo" <ja*****@texeme.com> wrote in message
news:43**************@texeme.com...

If I put that in a case statement condition -- would I have to also use
break; ?

or would it be

continue;
break;


Peter Rilling wrote:
"continue"

"Steve" <St***@discussions.microsoft.com> wrote in message
news:F8**********************************@microsof t.com...
C#

I am iterating through a collection of rows thus:

foreach(DataRow myRow in dsTable.Table[0].Rows)
{
..........
}

in this loop I have some conditions and when one is met I dont want it to
procede down the code, I want it to go back to the top of the loop and
process the next row in the collection. How do I do this?

In a previous life when programming with Progress you could do this:

myloop:
FOR EACH row:

IF myconditionismet THEN
NEXT myloop

........

END.

This is the kind of thing I am after.

Thanks

Steve



Feb 13 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.