This paper deals with the analytical property of the first Melnikov function for general Hamiltonian systems possessing a cuspidal loop of order 2 and its expansion at the Hamiltonian value corresponding to the loop. The explicit formulas for the first coefficients of the expansion have been given. We prove that at least 13 limit cycles can bifurcate from the cuspidal loop of order 2 under certain conditions. Then we consider the cyclicity of a cuspidal loop in some Li¨¦nard and Hamiltonian systems, and determine the number of limit cycles that can bifurcate from the perturbed system.