LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 02-27-2011, 08:33 PM   #1
michaelinux
Member
 
Registered: Apr 2009
Location: El Salvador
Distribution: Slackware -current
Posts: 166

Rep: Reputation: 17
C# Control cannot fall through from one case label to another?


I'm having this problem with this piece of code, and i don't really get what the problem is, maybe is because i am already too sleepy to concentrate enough but maybe you guys can help me:


switch(plazo){
case 1:
plazo = 12;
break;
case 2:
plazo = 24;
break;
case 3:
plazo = 36;
break;
default:
Console.WriteLine("Ingrese un plazo valido de 1 a 3");
}


sorry if you don't understand the messages printing, it's Spanish.
anyway the error says Control cannot fall through from one case label to another
and it highlights the switch statement, i had this switch within a do-while loop, and i thought that might be the problem. but it wasn't

i hope you can help me.
many thanks

Last edited by michaelinux; 02-27-2011 at 09:42 PM.
 
Old 02-27-2011, 08:42 PM   #2
corp769
Guru
 
Registered: Apr 2005
Posts: 5,798

Rep: Reputation: 978Reputation: 978Reputation: 978Reputation: 978Reputation: 978Reputation: 978Reputation: 978Reputation: 978
You are getting that error because in C#, every case needs to end with either goto, break, or return. The proper way for your example would be the following:

Code:
switch(plazo){
case 1:
plazo = 12;
break;
case 2:
plazo = 24;
break;
case 3:
plazo = 36;
break;
default:
Console.WriteLine("Ingrese un plazo valido de 1 a 3");
break;
}
 
Old 02-27-2011, 09:42 PM   #3
michaelinux
Member
 
Registered: Apr 2009
Location: El Salvador
Distribution: Slackware -current
Posts: 166

Original Poster
Rep: Reputation: 17
Quote:
Originally Posted by corp769 View Post
You are getting that error because in C#, every case needs to end with either goto, break, or return. The proper way for your example would be the following:

Code:
switch(plazo){
case 1:
plazo = 12;
break;
case 2:
plazo = 24;
break;
case 3:
plazo = 36;
break;
default:
Console.WriteLine("Ingrese un plazo valido de 1 a 3");
break;
}
Thank you very much that break solved it.
 
Old 02-27-2011, 10:19 PM   #4
corp769
Guru
 
Registered: Apr 2005
Posts: 5,798

Rep: Reputation: 978Reputation: 978Reputation: 978Reputation: 978Reputation: 978Reputation: 978Reputation: 978Reputation: 978
Not a problem.

Cheers,

Josh
 
  


Reply

Tags
error, problem, switch


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
trouble umounting with LABEL=label in fstab JosephS Debian 3 02-01-2010 06:25 AM
chassis fan speed control (case fan) wastingtime Linux - Hardware 12 12-02-2007 07:08 PM
Control case lighting from linux Napalm Llama Linux - Hardware 2 11-30-2005 09:53 AM
cd/case label maker program MRDucks Mandriva 2 10-24-2005 06:25 PM
case airflow, and fan control, HD cable question, and stress testing help a NEWBIE zetsui Linux - Hardware 3 03-17-2004 03:36 AM


All times are GMT -5. The time now is 11:54 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration