Control two output in one adruino

Hi everybody, I am a student and I am working a project that related to arduino. The purpose is control the pin 13 of on and off and pin9 by variable output. Both arduino programs are complete and its work individually. Here comes the question that I can't combine them together in one program.I have changed the instance and variable names and it didnt work anyway.Can someone help me?

For on and off

#include <SoftwareSerial.h>
#include <Wire.h>


int LED = 13;
SoftwareSerial I2CBT(10,11);

void setup() {
   
  Serial.begin(9600);
  I2CBT.begin(115200);//bluetooth baud rate  
  
  pinMode(LED, OUTPUT);    
}

///////////////////main///////////////////////////

void loop() {

  byte cmmd[20];
  int insize;
  
  while(1){
/*
read message from bluetooth
*/
    if ((insize=(I2CBT.available()))>0){
       Serial.print("input size = "); 
       Serial.println(insize);
       for (int i=0; i<insize; i++){
         Serial.print(cmmd[i]=char(I2CBT.read()));
         Serial.print("\n"); 
       }
      
    }  
      switch (cmmd[0]) {
        case 97: //"a"     
          
          digitalWrite(LED,HIGH);
          
          break;  
      case 98://"b"
          
          digitalWrite(LED,LOW);
          
          break;
   
      } //Switch
      
  } //while

}

For variable output

#include <SoftwareSerial.h>
#include <Wire.h>

SoftwareSerial I2CBT(10,11);  // RX,  TX

void setup() {
  Serial.begin(115200);
  I2CBT.begin(115200);//bluetooth baud rate
 
  pinMode(9,OUTPUT);
 
}

///////////////////main///////////////////////////

void loop() {

  byte cmmd[20];
  int insize;
  int a=0;
  while(2){
/*
read message from bluetooth
*/
    if ((insize=(I2CBT.available()))>0){
       Serial.print("input size = "); 
       Serial.println(insize);
       for (int i=0; i<insize; i++){
         //cmmd[i]=char(I2CBT.read());
         Serial.print(cmmd[i]=char(I2CBT.read()));
       }
       Serial.println("\n"); 
    }
    if(insize==4){  
      a = (cmmd[0]-48)*10;
      a=a+(cmmd[1]-48);
    }
    if(insize==3){
      a=(cmmd[0]-48);
    }
    Serial.println(a);
    analogWrite(9,map(a,0,80,0,255));
    
  } //while

}

This demo shows a simple way to merge two programs

...R

..and maybe post your attempt at combining them?