How to loop through a list of some doctype from script of another doctype

How to loop through a list of some doctype from script of another doctype.
For example I have doctype A and doctype B. I want to loop through doctype A List from script of doctype B.

Thanks.