Intramolecular aldol condensation
When the two carbonyl groups are in the same molecule, at the right distance, the aldol condensation is intramolecular and forms a ring. It is the most direct way of preparing cyclopentenones and cyclohexenones.
1,4-Diketones cyclize to cyclopent-2-enones and 1,5-diketones to cyclohex-2-enones:

Regioselectivity
A diketone can form several enolates, but under equilibrium conditions (base in a protic solvent, heat) all steps are reversible and the most stable product accumulates. Five- and six-membered rings form without strain; three- and four-membered rings, also possible in principle, are not formed, and if they are they revert by retro-aldol reaction:

If there is a choice between an aldehyde and a ketone as the electrophile, the more reactive aldehyde reacts. And if only one of the possible aldols can dehydrate to a conjugated enone, dehydration pulls all the equilibria towards it.
Applications in synthesis
The intramolecular aldol condensation can build new rings onto existing cyclic systems; the structure and stereochemistry of the product are dictated by the ring geometry and the proximity of the reactive groups, and it can even form bridgehead double bonds. There are also intramolecular versions of the Mukaiyama reaction that use acetals as precursors of the electrophile and can close eleven-membered rings, as in the synthesis of the jatrophanes.
From a retrosynthetic point of view, any bond between a carbinol carbon (or its equivalent, the β carbon of an enone) and a carbon α to a carbonyl group is a candidate for formation by an intramolecular aldol addition:

The most important application is the Robinson annulation, in which the 1,5-diketone is formed in the same flask by a Michael addition.
