QM eigenstate expansion

Why sometime we use the integral to expand the eigenstates and sometime we use the sum to expand? now i am read the modern quantum mechanics J.J.Sakurai text and confusing

Sometimes eigenvalues form a discrete spectrum,such as discrete energy levels in a potential well,so we use sum.But sometimes they form a continous spectrum,such as momentum of free particle,so we use the integral.

• And sometimes both (for instance, in an atom there are discrete energy levels but also a continuum of unbound states in which the electron is free) – zeldredge Nov 1 '17 at 14:00