This paper proposes a repetitive control type optimal gait generation framework by executing learning control and parameter tuning. We propose a learning optimal control method of Hamiltonian systems unifying iterative learning control (ILC) and iterative feedback tuning (IFT). It allows one to simultaneously obtain an optimal feedforward input and tuning parameter for a plant system, which minimizes a given cost function. In the proposed method, a virtual constraint by a potential energy prevents a biped robot from falling. The strength of the constraint is automatically mitigated by the IFT part of the proposed method, according to the progress of trajectory learning by the ILC part.