Click here to Skip to main content
15,897,891 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am using the following code to check color of the bus with the following code

In the first for loop if the color of the bus is red then I need to leave that color and check for the other colors in the second for loop. How can I give condition to that??
C#
for (int p = 3; p < cmnMsgIdsRYGbuses.Count; p++)
{
   for (int i = 200; i < a5; i++)
   {
      if ((cmnMsgIdsRYGbuses[p] == CANMsgIdList[i].MsgId)
         && ((CANMsgIdList[i].Bus) == (Buses.CANBusRed)
         || (CANMsgIdList[i].Bus) == (Buses.CANBusYellow)
         || (CANMsgIdList[i].Bus) == (Buses.CANBusGreen)
         || (CANMsgIdList[i].Bus) == (Buses.CANBusOrange)))
      {
         for (int k = i + 1; k < b5; k++)
         {
            if ((cmnMsgIdsRYGbuses[p] == CANMsgIdList[k].MsgId)
               && ((CANMsgIdList[k].Bus) == (Buses.CANBusYellow))
               && (CANMsgIdList[k].TimeStamp > CANMsgIdList[i].TimeStamp))
            {
               for (int m = k + 1; m < c5; m++)
               {
                  if ((cmnMsgIdsRYGbuses[p] == CANMsgIdList[m].MsgId)
                     && ((CANMsgIdList[m].Bus) == (Buses.CANBusGreen))
                     && (CANMsgIdList[m].TimeStamp > CANMsgIdList[k].TimeStamp))
                  {
                     //k = b5;
                     //m = c5;
                     for (int n = m + 1; n < d5; n++)
                     {
                        if ((cmnMsgIdsRYGbuses[p] == CANMsgIdList[n].MsgId)
                           && ((CANMsgIdList[n].Bus) == (Buses.CANBusOrange))
                           && (CANMsgIdList[n].TimeStamp > CANMsgIdList[m].TimeStamp))
                        {
                           //int i1 = i; int k1 = k; int m1 = m;
                           for (int f = k + 1; f < m; f++)
                           {
                              if ((CANMsgIdList[i].MsgId == CANMsgIdList[f].MsgId))
                              {
                                 if ((CANMsgIdList[f].Bus) == (Buses.CANBusYellow))
                                 {
                                    buffer1.Add(f);
                                    q6++;
                                 }
                                 if ((CANMsgIdList[f].Bus) != (Buses.CANBusYellow))
                                 {
                                    check6 = "Invalid bus";
                                 }
                              }
                           }
                           for (int f = i + 1; f < k; f++)
                           {
                              if ((CANMsgIdList[i].MsgId == CANMsgIdList[f].MsgId))
                              {
                                 if ((CANMsgIdList[f].Bus) == (Buses.CANBusRed))
                                 {
                                    buffer2.Add(f);
                                    q6++;
                                 }
                                 if ((CANMsgIdList[f].Bus) != (Buses.CANBusRed))
                                 {
                                    check6 = "Invalid bus";
                                 }
                              }
                           }
                           for (int f = m + 1; f < n; f++)
                           {
                              if ((CANMsgIdList[i].MsgId == CANMsgIdList[f].MsgId))
                              {
                                 if ((CANMsgIdList[f].Bus) == (Buses.CANBusGreen))
                                 {
                                    buffer5.Add(f);
                                    q6++;
                                 }
                                 if ((CANMsgIdList[f].Bus) != (Buses.CANBusGreen))
                                 {
                                    check6 = "Invalid bus";
                                 }
                              }
                           }
                           if (buffer1.Count != 0)
                           {
                              int largestVal = buffer1[0];
                              foreach (int temp in buffer1)
                              {
                                 if (temp > largestVal)
                                    largestVal = temp;
                                 f6 = largestVal;
                              }
                              for (int z = f6 + 1; z < k; z++)
                              {
                                 if ((CANMsgIdList[i].MsgId == CANMsgIdList[z].MsgId))
                                 {
                                    buffer3.Add(z);
                                 }
                              }
                              buffer1.Clear();
                           }
                           if (buffer2.Count != 0)
                           {
                              int largestVal = buffer2[0];
                              foreach (int temp in buffer3)
                              {
                                 if (temp > largestVal)
                                    largestVal = temp;
                                 g6 = largestVal;
                              }
                              for (int z = g6 + 1; z < m; z++)
                              {
                                 if ((CANMsgIdList[i].MsgId == CANMsgIdList[z].MsgId))
                                 {
                                    buffer4.Add(z);
                                 }
                              }
                              buffer2.Clear();
                           }
                           if (buffer5.Count != 0)
                           {
                              int largestVal = buffer5[0];
                              foreach (int temp in buffer3)
                              {
                                 if (temp > largestVal)
                                    largestVal = temp;
                                 j6 = largestVal;
                              }
                              for (int z = j6 + 1; z < n; z++)
                              {
                                 if ((CANMsgIdList[i].MsgId == CANMsgIdList[z].MsgId))
                                 {
                                    buffer6.Add(z);
                                 }
                              }
                              buffer5.Clear();
                           }
                           if ((buffer3.Count != 0) || (buffer4.Count != 0) || (check6 == "Invalid bus") || (buffer5.Count != 0))
                           {
                              k = b5;
                              m = c5;
                              n = d5;
                              check6 = null;
                              buffer3.Clear();
                              buffer4.Clear();
                              buffer6.Clear();
                           }
                           else
                           {
                              yellowTimeStampRYGOcmnMsgIds.Add(CANMsgIdList[k].TimeStamp);
                              redTimeStampRYGOcmnMsgIds.Add(CANMsgIdList[i].TimeStamp);
                              greenTimeStampRYGOcmnMsgIds.Add(CANMsgIdList[m].TimeStamp);
                              orangeTimeStampRYGOcmnMsgIds.Add(CANMsgIdList[n].TimeStamp);
                              GatewayRYGOmsgId.Add(CANMsgIdList[i].MsgId);
                              k = b5;
                              i = a5;
                              m = c5;
                              n = d5;
                           }
                        }
                     }
                  }
               }
            }
         }
      }
   }
}


Thanks
John
Posted
Updated 15-Jan-14 22:23pm
v3
Comments
Karthik_Mahalingam 16-Jan-14 3:40am    
post your second loop code
Member 10408451 16-Jan-14 3:47am    
Yes I posted it

In each for loop I need to leave the color detected in previous loop and check for other colors

How can I do it
Alexander Dymshyts 16-Jan-14 5:47am    
What are you trying to do in your loops?
Member 10408451 16-Jan-14 7:15am    
FIRST LOOP SAME MESSAGE ID AND ANY BUS COLOR(RED,YELLOW,GREEN,ORANGE)
IF FIRST LOOP IS RED COLOR
2ND LOOP SAME MSG ID AND ANY COLOR OTHER THAN RED
2ND LOOP IS YELLOW
3RD LOOP SAME MSG ID AND ANY COLOR OTHER THAN RED,YELLOW
3RD LOOP IS GREEN
4TH LOOP SAME MSG ID AND ANY COLOR OTHER THAN RED,YELLOW,GREEN(ORANGE)
SAVE THEM INTO A LIST
Alexander Dymshyts 16-Jan-14 8:27am    
No, in general what are you trying to do? Do you need to find a color, or what?

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