How do I jump to the Next row in a foreach

G

Guest

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
 
J

John Bailo

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


foreach ()

{

Do();

Do2();
Do3();

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

}

}
 
J

John Bailo

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

or would it be

continue;
break;




Peter said:
"continue"

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
 
A

Arnd Hurlbrink

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 said:
If I put that in a case statement condition -- would I have to also use
break; ?

or would it be

continue;
break;




Peter said:
"continue"

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top