Why do some elements exist as molecules and some as atoms?

By following different laws of chemical combination the chemical compounds
takes place as a result of combination of atoms of various elements in different ways.