Windows Develop Bookmark and Share   
 index > Windows Forms General > Control Cannot flow??
 

Control Cannot flow??

hi

for(int cnt=0;...)
{
switch(cnt)
case 1:
...
....
case 2:
....
...
}

i have a similar code.
but i'm getting an compilation error as follows:
"control cannot flow thro from one case lable to another."

can u help me with this?
what does it mean?
what should i do to rectify it??
Umesh_karthy_41cdd8  Tuesday, March 13, 2007 9:02 AM

Hi,

See the below code snippet works fine.Just check , it may help u findiing out ur error.otherwise it's better to have the code posted to find the error.

--------------------------------------------

using System;

using System.Collections.Generic;

using System.Text;

namespace ConsoleApplication1

{

class Program

{

static void Main(string[] args)

{

for(int cnt=1;cnt<6;cnt++)

{

Console.WriteLine("Loop Iteration");

switch(cnt)

{

case 1: Console.WriteLine("one"); break;

case 2: Console.WriteLine("two"); break;

case 3: Console.WriteLine("three"); break;

case 4: Console.WriteLine("four"); break;

case 5: Console.WriteLine("five"); break;

}

}

}

}

}

----------------------------------

Thanx,

Ch.T.Gopi Kumar.

TilakGopi  Tuesday, March 13, 2007 9:21 AM
Umesh_karthy_41cdd8 wrote:
hi

for(int cnt=0;...)
{
switch(cnt)
case 1:
...
....
case 2:
....
...
}

i have a similar code.
but i'm getting an compilation error as follows:
"control cannot flow thro from one case lable to another."

can u help me with this?
what does it mean?
what should i do to rectify it??


One or more of your "case" statements does not have a break command:

switch (variableName) {
case value1:
// .. some code goes here.
case value2:
// .. some more code here.
}

Whereas this would work:

switch (variableName) {
case value1:
// .. some code goes here.
break;
case value2:
// .. some more code here.
break;
}
rusynaptic  Tuesday, March 13, 2007 7:48 PM

Hi, Umesh_karthy_41cdd8

Yes, you've lost break keywords. Put it in your mind that case is just used as a sign, like a sign for goto statement.

If you don't put break after case the switch logic can't be accomplished well, so the compile error occurred.

You may first learn how to use switch keywords: http://msdn2.microsoft.com/en-us/library/06tc147t(VS.80).aspx

Thanks

Figo Fei  Wednesday, March 14, 2007 9:30 AM

Hi,

See the below code snippet works fine.Just check , it may help u findiing out ur error.otherwise it's better to have the code posted to find the error.

--------------------------------------------

using System;

using System.Collections.Generic;

using System.Text;

namespace ConsoleApplication1

{

class Program

{

static void Main(string[] args)

{

for(int cnt=1;cnt<6;cnt++)

{

Console.WriteLine("Loop Iteration");

switch(cnt)

{

case 1: Console.WriteLine("one"); break;

case 2: Console.WriteLine("two"); break;

case 3: Console.WriteLine("three"); break;

case 4: Console.WriteLine("four"); break;

case 5: Console.WriteLine("five"); break;

}

}

}

}

}

----------------------------------

Thanx,

Ch.T.Gopi Kumar.

TilakGopi  Tuesday, March 13, 2007 9:21 AM
Umesh_karthy_41cdd8 wrote:
hi

for(int cnt=0;...)
{
switch(cnt)
case 1:
...
....
case 2:
....
...
}

i have a similar code.
but i'm getting an compilation error as follows:
"control cannot flow thro from one case lable to another."

can u help me with this?
what does it mean?
what should i do to rectify it??


One or more of your "case" statements does not have a break command:

switch (variableName) {
case value1:
// .. some code goes here.
case value2:
// .. some more code here.
}

Whereas this would work:

switch (variableName) {
case value1:
// .. some code goes here.
break;
case value2:
// .. some more code here.
break;
}
rusynaptic  Tuesday, March 13, 2007 7:48 PM

Hi, Umesh_karthy_41cdd8

Yes, you've lost break keywords. Put it in your mind that case is just used as a sign, like a sign for goto statement.

If you don't put break after case the switch logic can't be accomplished well, so the compile error occurred.

You may first learn how to use switch keywords: http://msdn2.microsoft.com/en-us/library/06tc147t(VS.80).aspx

Thanks

Figo Fei  Wednesday, March 14, 2007 9:30 AM

You can use google to search for other answers

Custom Search

More Threads

• Working with the Clipboard() class!
• spliting data in the crystal report?
• Moving multiple top level forms synchronously
• Question on Copying selected items from a ListBox to a text file in Vb.net
• Extract information from audio cd - like a cue sheet
• button closes winform
• Screen Capture...
• Multiple Controls. TLayoutPanel
• Translate code from C# to VB.Net
• Need help on way of storing Data - Any advice would rock.