An approach to loop prediction that starts with a database search is presented and analyzed. To obtain meaningful statistics, 130 loops from 21 proteins were studied. The correlation between the internal conformation of the loop and the conformation of the neighboring stem residues was examined. Distances between Cα and Cβ of the immediate neighbor residues at each end select template loops as well as more complex (e.g. three residues on either side) matching criteria. To have a high probability that the best possible loop candidate in the database is included in the set, relatively large cutoffs for matching the interatomic distances of the stem residues have to be used in the template loop selection procedure; for loops of length 5, this results in an average of 1000 loops and for loops of length 9, the number is about 1500. The required number increases only slowly with loop length, in contrast to the exponential time increase involved in direct searches of the conformational space. The best loops among the large number of candidates can be determined by ranking them with the standard CHARMM non-bonded energy function (without electrostatics) applied to the backbone and Cβ atoms. The same representation (backbone plus Cβ) can be used to optimize the loop orientations relative to the rest of the protein by constrained energy minimization. Target loops that have many non-bonded contacts with the protein yield better results so that analysis of the non-bonded contacts of the selected template loops is useful in determining the expected accuracy of a prediction. The method for loop selection and optimization predicted eight (out of 18) loops of up to nine residues to an RMSD better than 1.07 Å relative to the crystal structure; for 17 of the 18 loops, one of the three lowest energy template loops had an RMSD of less than 1.79 Å. The prediction of antibody loops from a database search is more effective than that for non-antibody loops. Provided that they belong to one of the canonical classes, very similar antibody loops are certain to exist in the database. Superposition of the stem residues for antibody loops also results in a better orientation than with arbitrary target loops because the neighboring residues tend to have a more similar β-strand structure. Two H3 loops (for which no canonical structures have been proposed) were predicted with reasonable accuracy (RMSD of 0.49 Å and 1.07 Å) even though no corresponding antibody loops were in the database.