Car A is traveling at 20 miles per hour. Car B is 1 mile behind, following at 30 miles per hour. A fast fly can move at 40 miles per hour. The fly begins on the front bumper of car B, and flies back and forth between the two cars. How many miles will the fly travel before it is crushed in the collision?
1. **Determine the time it takes for Car B to catch up to Car A:**
   - Car A is traveling at 20 miles per hour.
   - Car B is traveling at 30 miles per hour and is 1 mile behind Car A.
   - The relative speed of Car B with respect to Car A is \(30 - 20 = 10\) miles per hour.
   - The time \(t\) it takes for Car B to catch up to Car A is given by:
     \[
     t = \frac{\text{distance}}{\text{relative speed}} = \frac{1 \text{ mile}}{10 \text{ miles per hour}} = \frac{1}{10} \text{ hours}
     \]

2. **Calculate the distance the fly travels:**
   - The fly moves at a constant speed of 40 miles per hour.
   - The time the fly has to travel before the collision is \(\frac{1}{10}\) hours.
   - The distance \(d\) the fly travels is given by:
     \[
     d = \text{speed} \times \text{time} = 40 \text{ miles per hour} \times \frac{1}{10} \text{ hours} = 4 \text{ miles}
     \]

Conclusion:
\[
\boxed{4}
\]