One of the important issues for cognitive radar is how to optimally decide or select the radar waveform for the next transmission based on the observation of past radar returns. In this paper, with the stochastic dynamic programming model of waveform scheduling, the optimal algorithm of waveform scheduling is proposed. In order to solve the problem that we can not compute the exact value function under some circumstances, we step forward in time using an approximation of the value function from the previous iteration. The simulation results testify validity of our algorithm.