DHT11 source file

i am not much experienced to C programming and i encounter many difficulties to understand the DHT11 sketch and dht11.cpp file.could someone please explain step by step this part of the code?its the part which sends the 40 bits of temperature and humidity data .i would be very thankful for explanation. :~

for (int i=0; i<40; i++)
{
loopCnt = 10000;
while(digitalRead(pin) == LOW)
if (loopCnt-- == 0) return -2;

unsigned long t = micros();

loopCnt = 10000;
while(digitalRead(pin) == HIGH)
if (loopCnt-- == 0) return -2;

if ((micros() - t) > 40) bits[idx] |= (1 << cnt);
if (cnt == 0) // next byte?
{
cnt = 7; // restart at MSB
idx++; // next byte!
}
else cnt–;
}

This code does not send 40 bits but receives them. It waits for the input pin to become HIGH and then measures the time it stays HIGH. If that time is greater than 40µs it saves a 1 bit otherwise it saves a 0 bit. The loopCnt variable ensures that the read times out if the communication doesn't take place.

the bits are placed in 5 bytes (of 8 bits)
it could also have been a nested loop iso one loop

for (int b=0; b<5; b++)
{
  byte bb = 0;
  for (int  bit=7; bit >=0; bit++)
  {
    // read 1 bit
   ... similar code here
  }
  bits[b] = bb;
}

The nr 10000 is a magic number, on a uno it is timeouts after ~50milliseconds