As, when and while are conjunctions. In some uses as, when and while can mean the same, but they can also have slightly different meanings. We use them to introduce subordinate clauses.
We can use as, when and while to mean ‘during the time that’, to connect two events happening at the same time:
Another coach-load of people arrived as we were leaving.
We often use them with the past continuous to refer to background events:
When the men were out working in the field, I helped with milking the cows, feeding the calves and the pigs.
While he was working, he often listened to music.
We can put clauses with as, when and while before or after the main clause. When they come before the main clause, we use a comma:
As she was leaving the court, a crowd of photographers gathered around her. (before the main clause, followed by a comma)
Steven was very unhappy when things weren’t going well for him.
Lucy came into the room while he was waiting.
We can use as to introduce two events happening at the same time. After as, we can use a simple or continuous form of the verb. The continous form emphasises an action that interrupts or occurs during the progress of another action:
As she walked to the door, she thanked them for a lovely dinner.
As they were signing the contract, they noticed that a page was missing.
We can use when to introduce a single completed event that takes place in the middle of a longer activity or event. In these cases, we usually use a continuous verb in the main clause to describe the background event:
He was walking back to his flat when he heard an explosion.
Depending on the context, when can mean ‘after’ or ‘at the same time’.