473,395 Members | 1,526 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,395 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 3511
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.