473,396 Members | 1,840 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

help on "continue" - C#

As per this URL
http://msdn.microsoft.com/library/en...asp?frame=true
conitnue works on for, while, do... I know it works for foreach as well as
I'm using it somewhere.

My question is how do I "continue" (jump an iteration) of an outermost loop
from an inner loop.

So I have something like this:

foreach(foo)
{
foreach(blah blah)
{
for(i= gooo gooo)
{
continue; (I want this continue to jump an iteration of the
foreach(foo foo)
}
}
}

Thank you in anticipation!
Harman Sahni
Nov 22 '05 #1
3 3512
Hi Harman,

C# does not support "continue <label>", instead use Goto (but only if you
really have to ;-)

example:

static void Foo()
{
int[] ArrayOne = new int[] { 1, 2, 3 };
int[] ArrayTwo = new int[] { 10, 20, 30 };
int[] ArrayThree = new int[] { 100, 200, 300 };
foreach(int i in ArrayOne)
{
Console.WriteLine(i);
foreach(int j in ArrayTwo)
{
Console.WriteLine(j);
foreach(int k in ArrayThree)
{
Console.WriteLine(k);
if (k >= 200)
{
goto done;
}
}
}
}
done: Console.WriteLine("We are done");
}

Regards,

Bennie Haelen
"Harman Sahni" <Ha*********@Hotmail.com> wrote in message
news:uY****************@TK2MSFTNGP09.phx.gbl...
As per this URL
http://msdn.microsoft.com/library/en...asp?frame=true
conitnue works on for, while, do... I know it works for foreach as well as
I'm using it somewhere.

My question is how do I "continue" (jump an iteration) of an outermost loop from an inner loop.

So I have something like this:

foreach(foo)
{
foreach(blah blah)
{
for(i= gooo gooo)
{
continue; (I want this continue to jump an iteration of the
foreach(foo foo)
}
}
}

Thank you in anticipation!
Harman Sahni

Nov 22 '05 #2
Gotcha!

I guess I have to use it then coz I can't see how else one can jump
iteration from within nested foreach loops.

Thx!
Harman

"Bennie Haelen" <Be***********@jda.com> wrote in message
news:OQ*************@TK2MSFTNGP11.phx.gbl...
Hi Harman,

C# does not support "continue <label>", instead use Goto (but only if you
really have to ;-)

example:

static void Foo()
{
int[] ArrayOne = new int[] { 1, 2, 3 };
int[] ArrayTwo = new int[] { 10, 20, 30 };
int[] ArrayThree = new int[] { 100, 200, 300 };
foreach(int i in ArrayOne)
{
Console.WriteLine(i);
foreach(int j in ArrayTwo)
{
Console.WriteLine(j);
foreach(int k in ArrayThree)
{
Console.WriteLine(k);
if (k >= 200)
{
goto done;
}
}
}
}
done: Console.WriteLine("We are done");
}

Regards,

Bennie Haelen
"Harman Sahni" <Ha*********@Hotmail.com> wrote in message
news:uY****************@TK2MSFTNGP09.phx.gbl...
As per this URL
http://msdn.microsoft.com/library/en...asp?frame=true conitnue works on for, while, do... I know it works for foreach as well as I'm using it somewhere.

My question is how do I "continue" (jump an iteration) of an outermost

loop
from an inner loop.

So I have something like this:

foreach(foo)
{
foreach(blah blah)
{
for(i= gooo gooo)
{
continue; (I want this continue to jump an iteration of the
foreach(foo foo)
}
}
}

Thank you in anticipation!
Harman Sahni


Nov 22 '05 #3
You can do it by adding flag variable:

bool jumpOut=false;

foreach (foo1)
{
foreach ( foo2)
{
foreach (foo3)
{
if (someCondition)
{
jumpOut=true;
break;
}
}

if (jumpOut) break;
}

if (jumpOut) continue; //ignore below doSomething() and go next loop

//other steps
doSomething()
}
"Harman Sahni" <Ha*********@Hotmail.com> wrote in message
news:%2******************@TK2MSFTNGP09.phx.gbl...
Gotcha!

I guess I have to use it then coz I can't see how else one can jump
iteration from within nested foreach loops.

Thx!
Harman

"Bennie Haelen" <Be***********@jda.com> wrote in message
news:OQ*************@TK2MSFTNGP11.phx.gbl...
Hi Harman,

C# does not support "continue <label>", instead use Goto (but only if you
really have to ;-)

example:

static void Foo()
{
int[] ArrayOne = new int[] { 1, 2, 3 };
int[] ArrayTwo = new int[] { 10, 20, 30 };
int[] ArrayThree = new int[] { 100, 200, 300 };
foreach(int i in ArrayOne)
{
Console.WriteLine(i);
foreach(int j in ArrayTwo)
{
Console.WriteLine(j);
foreach(int k in ArrayThree)
{
Console.WriteLine(k);
if (k >= 200)
{
goto done;
}
}
}
}
done: Console.WriteLine("We are done");
}

Regards,

Bennie Haelen
"Harman Sahni" <Ha*********@Hotmail.com> wrote in message
news:uY****************@TK2MSFTNGP09.phx.gbl...
As per this URL
http://msdn.microsoft.com/library/en...asp?frame=true conitnue works on for, while, do... I know it works for foreach as
well as I'm using it somewhere.

My question is how do I "continue" (jump an iteration) of an outermost

loop
from an inner loop.

So I have something like this:

foreach(foo)
{
foreach(blah blah)
{
for(i= gooo gooo)
{
continue; (I want this continue to jump an iteration of the
foreach(foo foo)
}
}
}

Thank you in anticipation!
Harman Sahni



Nov 22 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Harman Sahni | last post by:
As per this URL http://msdn.microsoft.com/library/en-us/vjref98/html/14_14.asp?frame=true conitnue works on for, while, do... I know it works for foreach as well as I'm using it somewhere. My...
14
by: Daniel Bass | last post by:
is there an equivalent key word for C++'s "continue" in VB (.net) in this context? CString szLine; szLine = myReader.ReadLine(); while ( !szLine.IsEmpty() ) { if ( szLine(0) == '-' ) {
14
by: Jan Schmidt | last post by:
Hi, in a nested do-while-loop structure I would like to "continue" the outer loop. With goto this should be no problem in while-loops. However, for do-while I cannot get it to work (without a...
4
by: Curious | last post by:
I have two buttons on a form, "Pause" and "Continue". When "Pause" button is clicked, it should: 1) Stop the background worker; and, 2) Enable the "Continue" button. I have the code below...
13
by: xz | last post by:
What if I want the following: vector<intv; // v is loaded by push_back() switch( v.size() ) { case 2: //do something
36
by: mdh | last post by:
May I ask the group this somewhat non-focused question....having now seen "continue" used in some of the solutions I have worked on. ( Ex 7-4 solution by Tondo and Gimpel comes to mind) Is there a...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.