He was sleeping for five hours when he heard a loud explosion.
He had been sleeping for five hours when he heard a loud explosion.
I believe both sentences are correct. Am I correct to say so?
Watch out for these words:before,after,while,during,when...they are time adverbs which agree with past perfect or past perfect progressive verbs...'He slept before I returned(incorrect) 'He had slept before I returned(correct(past perfect) ) or 'He had been sleeping before I returned'(correct(past perfect progressive) )
He changed before he left.
He left after I arrived.
She washed up while I was finishing my reports.
George looked unhappy when I told him the news.
In the original sentence, when is a conjunction.
During is a preposition.