While or when? = to join 2 actions in the past
while + long action => past continuous
when + short action => simple past
I was walking past the car when it exploded.
When the car exploded, I was walking past it. <- comma
The car exploded while I was walking past it.
While I was walking past the car, it exploded. <- comma