how can I condense a repetitive task into a loop.

Well, it is. It is writing to position 0 of the array.

I’ve played around a bit with the program since last night and have now got a circuit built up on a breadboard that gives me 8 switches and 8 leds. I have set up the program to set bits 1 and 4 high if the switches are on. I can switch 1 and/or 4 on and get the relevant leds to light. If I comment out the line
xBitNum[b} = shiftIn(dataPin, clockPin); (remember I have altered the bracket to prevent it turning to bold)
The array doesn’t fill with the info from the shift register.
If this line isn’t filling the array which is? How is it doing it without the variable b incrementing (or decrementing as the for loop later does)?
The whole sketch is below.

int xBitNum[9];
int i;
int b;
int dataPin = 9;
int clockPin = 7;
int latchPin = 8;
int ledoutPin10 = 10;
int ledoutPin11 = 11;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);//set up to send info to monitor
  pinMode(clockPin, OUTPUT); //send a clock pulse to tell shift register to send next info 
  pinMode(dataPin, INPUT);//read next shift register state
  pinMode(latchPin, OUTPUT);//set to 1 to collect data, 0 to write data to arduino
  pinMode(ledoutPin10, OUTPUT);//set pin/s to test array
  pinMode(ledoutPin11, OUTPUT);//set pin/s to test array
  
}

void loop() {
  //Pulse the latch pin:
  //set it to 1 to collect parallel data
  digitalWrite(latchPin,1);
  //set it to 1 to collect parallel data, wait
  delayMicroseconds(20);
  //set it to 0 to transmit data serially  
  digitalWrite(latchPin,0);
  for (i=8; i>0; i--)
   {
    Serial.print (i); 
    Serial.print (xBitNum[i]);
    Serial.print ("  ");
   }
   Serial.println();//add a return to move the monitor signal down 1 line
   if (xBitNum[1] == 1)
  {
    digitalWrite (ledoutPin11, HIGH);
  }
  else
  {
    digitalWrite (ledoutPin11, LOW);
  }    
  if (xBitNum[4] == 1)
  {
    digitalWrite (ledoutPin10, HIGH);
  }
  else
  {
    digitalWrite (ledoutPin10, LOW);
  }
 
   xBitNum[b] = shiftIn(dataPin, clockPin);  //write into array from shift register  
 
 
}
//end of loop
//sub routine instead of using the library shift reg?
byte shiftIn(int myDataPin, int myClockPin) { 
  int i;
  int temp = 0;
  int pinState;
  byte myDataIn = 0;
  pinMode(myClockPin, OUTPUT);
  pinMode(myDataPin, INPUT);
  //we will be holding the clock pin high 8 times (0,..,7) at the
  //end of each time through the for loop
  //at the begining of each loop when we set the clock low, it will
  //be doing the necessary low to high drop to cause the shift
  //register's DataPin to change state based on the value
  //of the next bit in its serial information flow.
  //The register transmits the information about the pins from pin 7 to pin 0
  //so that is why our function counts down
  for (i=8; i>0; i--)
  {
    digitalWrite(myClockPin, 0);
    delayMicroseconds(0.2);
    temp = digitalRead(myDataPin);
    xBitNum[i] = temp;
    if (temp) {
      pinState = 1;
      //set the bit to 0 no matter what
      myDataIn = myDataIn | (1 << i);
    }
    else 
    {
      pinState = 0;
    }
    digitalWrite(myClockPin, 1);//move shift register on to next bit
  }
   return myDataIn;//end of subroutine
}

(remember I have altered the bracket to prevent it turning to bold)

You can put a single line into code tags to stop that.

If this line isn't filling the array which is?

This function:

  for (i=8; i>0; i--)
  {
    digitalWrite(myClockPin, 0);
    delayMicroseconds(0.2);
    temp = digitalRead(myDataPin);
    xBitNum[i] = temp;

I thought it had to be that line but that then still begs the question what does the line

   xBitNum[b} = shiftIn(dataPin, clockPin);

do and why does it stop the monitor printing the contents of the array (I am assuming the array must fill) when I comment the line out?

but that then still begs the question what does the line...do

You wrote the code. You put that statement in there. You tell US why.

and why does it stop the monitor printing the contents of the array

I've seen no proof that it does. To generate that proof, you need more Serial.print() statements. Figure out exactly where the program stops.