They can sometimes be used interchangeably, but 'when' usually introduces a point in time and 'while' usually introduces a continuing activity during which something else occurred: When I first saw her, I fell in love. While we were talking, her boyfriend arrived.
New words, one handy idiom, and a 2-minute quiz — delivered to your inbox to keep your streak alive.