[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Unreachable code

Posted on 2004-11-29
8
Medium Priority
?
242 Views
Last Modified: 2010-04-15
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);
                              }
                        }                        
                  }
0
Comment
Question by:Tom Knowlton
  • 4
  • 4
8 Comments
 
LVL 5

Author Comment

by:Tom Knowlton
ID: 12700029
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
 
LVL 16

Accepted Solution

by:
muzzy2003 earned 2000 total points
ID: 12700039
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
 
LVL 5

Author Comment

by:Tom Knowlton
ID: 12700042
Experts please read this:  I intend to ask this to be marked as

PAQ / Refund Points.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 5

Author Comment

by:Tom Knowlton
ID: 12700047
muzzy:

Would you like the points?

Does not matter to me either way.
0
 
LVL 16

Expert Comment

by:muzzy2003
ID: 12700078
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
 
LVL 16

Expert Comment

by:muzzy2003
ID: 12700090
Sorry - just realised my post was before yours anyway, so you knew that. Anyway, comments stand.
0
 
LVL 5

Author Comment

by:Tom Knowlton
ID: 12700112
Enjoy!!!

Tom
0
 
LVL 16

Expert Comment

by:muzzy2003
ID: 12700130
OK, thanks very much.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question