I have a situation where multiple cases within a switch case operation use common code. The only difference between the cases is that I need to set up some counter variables to be unique for each case. Instead of duplicating the common code is there a way to set up the variables based on the case and then direct flow to the common code? I can't just put the common code at the end of the switch statement since the case statements below are embedded in alot of other case statements. See the cumbersome way (duplicating the common code for each case) of doing this below - the common code is in red:

Code:
switch(input)
{
	case 1:
	    i=0;
              	    k=5;
               
	   while (i< k)
                  {
                     if (mode == DATASTREAM)
                     {
                        for(j=0; j<5; j++)
                        {
                           if(C_Support & (1 << j))
                           {
                              msg_data[msg_idx++] = GET_BYTE_A(p_emm_timer1[i]);
                              msg_data[msg_idx++] = GET_BYTE_B(p_emm_timer1[i]);
                              msg_data[msg_idx++] = GET_BYTE_C(p_emm_timer1[i]);
                              msg_data[msg_idx++] = GET_BYTE_D(p_emm_timer1[i]);
                              msg_data[msg_idx++] = GET_BYTE_A(p_emm_timer2[i]);
                              msg_data[msg_idx++] = GET_BYTE_B(p_emm_timer2[i]);
                              msg_data[msg_idx++] = GET_BYTE_C(p_emm_timer2[i]);
                              msg_data[msg_idx++] = GET_BYTE_D(p_emm_timer2[i]);
                           }
                           else msg_idx += 8;
                        }
                     }
	      i++;
                  }	break;

	case 0x82:
               i=4;
               k=10;

	   while (i< k)
                  {
                     if (mode == DATASTREAM)
                     {
                        for(j=0; j<5; j++)
                        {
                           if(C_Support & (1 << j))
                           {
                              msg_data[msg_idx++] = GET_BYTE_A(p_emm_timer1[i]);
                              msg_data[msg_idx++] = GET_BYTE_B(p_emm_timer1[i]);
                              msg_data[msg_idx++] = GET_BYTE_C(p_emm_timer1[i]);
                              msg_data[msg_idx++] = GET_BYTE_D(p_emm_timer1[i]);
                              msg_data[msg_idx++] = GET_BYTE_A(p_emm_timer2[i]);
                              msg_data[msg_idx++] = GET_BYTE_B(p_emm_timer2[i]);
                              msg_data[msg_idx++] = GET_BYTE_C(p_emm_timer2[i]);
                              msg_data[msg_idx++] = GET_BYTE_D(p_emm_timer2[i]);
                           }
                           else msg_idx += 8;
                        }
                     }
	      i++;
                  }	break;
               
	case 0x89:
                i=8;
                k=15;

	   while (i< k)
                  {
                     if (mode == DATASTREAM)
                     {
                        for(j=0; j<5; j++)
                        {
                           if(C_Support & (1 << j))
                           {
                              msg_data[msg_idx++] = GET_BYTE_A(p_emm_timer1[i]);
                              msg_data[msg_idx++] = GET_BYTE_B(p_emm_timer1[i]);
                              msg_data[msg_idx++] = GET_BYTE_C(p_emm_timer1[i]);
                              msg_data[msg_idx++] = GET_BYTE_D(p_emm_timer1[i]);
                              msg_data[msg_idx++] = GET_BYTE_A(p_emm_timer2[i]);
                              msg_data[msg_idx++] = GET_BYTE_B(p_emm_timer2[i]);
                              msg_data[msg_idx++] = GET_BYTE_C(p_emm_timer2[i]);
                              msg_data[msg_idx++] = GET_BYTE_D(p_emm_timer2[i]);
                           }
                           else msg_idx += 8;
                        }
                     }
	      i++;
                  }	break;