Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
private void PlaceRandom()
{
int r, c;
r = 10; c = 10;
int i = 0;
ar = 0;
ac = 0;
Random rnd = new Random();
int val;
while (i < 8)
{
val = rnd.Next(9);
if (numNotExists(val) == true && val > 0)
{
pos[ar, ac] = val;

switch (val)
{
case 1:
lbl1.Location = new Point(c, r);

break;
case 2:
lbl2.Location = new Point(c, r);

break;
case 3:
lbl3.Location = new Point(c, r);

break;
case 4:
lbl4.Location = new Point(c, r);

break;
case 5:
lbl5.Location = new Point(c, r);

break;
case 6:
lbl6.Location = new Point(c, r);

break;
case 7:
lbl7.Location = new Point(c, r);

break;
case 8:
lbl8.Location = new Point(c, r);

break;
default:

}
c += 100;
ac++;
if (ac > 2)
{
ac = 0;
ar++;
}
if (c > 300)
{
c = 10;
r += 100;
}
i++;
}
else
continue;
}
lblBlank.Location = new Point(c, r);
pos[2, 2] = 9;
}




it showing an error "control cannot fall through from one case label ('default:') to another" at the default statement of the switch case i cant understand why
and what could be the reson
Posted
Comments
Sergey Alexandrovich Kryukov 23-Jun-14 16:39pm    
The whole idea to use this long case statement is pretty much illiterate. Have all the labels involved in some array and make it all in one statement. What you write is not maintainable. Everything is hard-coded, and so on. It makes no sense to review and fix this code. Better start over, write it in cultured and neat manner. Need any help with that? Remove all hard-coded immediate contants, remove all places when similar code is repeated...
—SA

1 solution

Add break; in default case as fall through is not allowed in C#
C#
default:
 break;
}


Please go through this link for details of switch statement
http://www.dotnetperls.com/case
 
Share this answer
 
v5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900