Unreachable code

I do not understand why this portion of my code is considered "unreachable" by the compiler:


                  switch(type)
                                    {
                                          case("SelfEmployed"):return SelfEmployed;
                                                break;
                                          case("ActiveMilitary"):return ActiveMilitary;
                                                break;
                                          case("WorkForRelative"):return WorkForRelative;
                                                break;
                                          default:
                                                return 1;
                                                break;
                                    }
                  




Here is the function:



public int MPPQuestionsStatus(long tempEntryID, string TempConnectionString, string type)
                  {
                        string strTempSQL = "";

                        int SelfEmployed=0;
                        int ActiveMilitary=0;
                        int WorkForRelative=0;

                        string SelfEmployedRaw="";
                        string ActiveMilitaryRaw="";
                        string WorkForRelativeRaw="";



      
                        strTempSQL = "ShowMPPAnswers " + tempEntryID.ToString();
               
                        //Create DataSet
                        SqlConnection TempConnection = new SqlConnection(TempConnectionString);
                        SqlDataAdapter TempDataAdapter = new SqlDataAdapter(strTempSQL,TempConnection);
                        DataSet TempDataSet = new DataSet();
                        TempDataAdapter.Fill(TempDataSet, "Temp");
                        DataTable TempDataTable = TempDataSet.Tables["Temp"];
                        SqlCommandBuilder TempCmdBuilder = new SqlCommandBuilder(TempDataAdapter);                  

                        foreach (DataRow myDataRow in TempDataSet.Tables["Temp"].Rows)
                        {
                              try
                              {
                                    
                                    SelfEmployedRaw = myDataRow.IsNull("self-employed") ? "No" : myDataRow["self-employed"].ToString();
                                    ActiveMilitaryRaw = myDataRow.IsNull("Active Military") ? "No" : myDataRow["Active Military"].ToString();
                                    WorkForRelativeRaw = myDataRow.IsNull("work for relative") ? "No" : myDataRow["work for relative"].ToString();

                                    switch(SelfEmployedRaw)
                                    {
                                          case("No"):SelfEmployed = 0;
                                                break;
                                          case("Yes"):SelfEmployed = 1;
                                                break;
                                          default:
                                                SelfEmployed = 1;
                                                break;
                                    }

                                    switch(ActiveMilitaryRaw)
                                    {
                                          case("No"):ActiveMilitary = 0;
                                                break;
                                          case("Yes"):ActiveMilitary = 1;
                                                break;
                                          default:
                                                ActiveMilitary = 1;
                                                break;
                                    }


                                    switch(WorkForRelativeRaw)
                                    {
                                          case("No"):WorkForRelative = 0;
                                                break;
                                          case("Yes"):WorkForRelative = 1;
                                                break;
                                          default:
                                                WorkForRelative = 1;
                                                break;
                                    }

                                    switch(type)
                                    {
                                          case("SelfEmployed"):return SelfEmployed;
                                                break;
                                          case("ActiveMilitary"):return ActiveMilitary;
                                                break;
                                          case("WorkForRelative"):return WorkForRelative;
                                                break;
                                          default:
                                                return 1;
                                                break;
                                    }
                              }
                              catch(Exception e)
                              {
                                    System.Diagnostics.Debug.WriteLine(e.Message + ":::::::" + e.StackTrace);
                              }
                        }                        
                  }
LVL 5
Tom KnowltonWeb developerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Tom KnowltonWeb developerAuthor Commented:
Here was my solution:



                  public int MPPQuestionsStatus(long tempEntryID, string TempConnectionString, string type)
                  {
                        string strTempSQL = "";

                        int SelfEmployed=0;
                        int ActiveMilitary=0;
                        int WorkForRelative=0;

                        string SelfEmployedRaw="";
                        string ActiveMilitaryRaw="";
                        string WorkForRelativeRaw="";

                        int FinalAnswer=1;



      
                        strTempSQL = "ShowMPPAnswers " + tempEntryID.ToString();
               
                        //Create DataSet
                        SqlConnection TempConnection = new SqlConnection(TempConnectionString);
                        SqlDataAdapter TempDataAdapter = new SqlDataAdapter(strTempSQL,TempConnection);
                        DataSet TempDataSet = new DataSet();
                        TempDataAdapter.Fill(TempDataSet, "Temp");
                        DataTable TempDataTable = TempDataSet.Tables["Temp"];
                        SqlCommandBuilder TempCmdBuilder = new SqlCommandBuilder(TempDataAdapter);                  

                        foreach (DataRow myDataRow in TempDataSet.Tables["Temp"].Rows)
                        {
                              try
                              {
                                    
                                    SelfEmployedRaw = myDataRow.IsNull("self-employed") ? "No" : myDataRow["self-employed"].ToString();
                                    ActiveMilitaryRaw = myDataRow.IsNull("Active Military") ? "No" : myDataRow["Active Military"].ToString();
                                    WorkForRelativeRaw = myDataRow.IsNull("work for relative") ? "No" : myDataRow["work for relative"].ToString();

                                    switch(SelfEmployedRaw)
                                    {
                                          case("No"):SelfEmployed = 0;
                                                break;
                                          case("Yes"):SelfEmployed = 1;
                                                break;
                                          default:
                                                SelfEmployed = 1;
                                                break;
                                    }

                                    switch(ActiveMilitaryRaw)
                                    {
                                          case("No"):ActiveMilitary = 0;
                                                break;
                                          case("Yes"):ActiveMilitary = 1;
                                                break;
                                          default:
                                                ActiveMilitary = 1;
                                                break;
                                    }


                                    switch(WorkForRelativeRaw)
                                    {
                                          case("No"):WorkForRelative = 0;
                                                break;
                                          case("Yes"):WorkForRelative = 1;
                                                break;
                                          default:
                                                WorkForRelative = 1;
                                                break;
                                    }

                                    switch(type)
                                    {
                                          case("SelfEmployed"):FinalAnswer = SelfEmployed;
                                                break;
                                          case("ActiveMilitary"):FinalAnswer = ActiveMilitary;
                                                break;
                                          case("WorkForRelative"):FinalAnswer =  WorkForRelative;
                                                break;
                                          default:
                                                FinalAnswer = 1;
                                                break;
                                    }//end switch                              

                              }//end try
                              catch(Exception e)
                              {
                                    System.Diagnostics.Debug.WriteLine(e.Message + ":::::::" + e.StackTrace);
                              }                              
                        }      
                  
                        return FinalAnswer;
                  }
0
muzzy2003Commented:
In the:

return 1;
break;

that you had, the return 1 prevents the break being reached. You can actually, in this case, omit the break statement I think.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Tom KnowltonWeb developerAuthor Commented:
Experts please read this:  I intend to ask this to be marked as

PAQ / Refund Points.
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

Tom KnowltonWeb developerAuthor Commented:
muzzy:

Would you like the points?

Does not matter to me either way.
0
muzzy2003Commented:
If you hadn't understood why your change fixed things and you now do, then feel free to give me some. Won't be in the least bit offended if you don't - I hadn't seen your last post when I posted mine.
0
muzzy2003Commented:
Sorry - just realised my post was before yours anyway, so you knew that. Anyway, comments stand.
0
Tom KnowltonWeb developerAuthor Commented:
Enjoy!!!

Tom
0
muzzy2003Commented:
OK, thanks very much.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.