The aim of this paper is to construct a dynamic programming algorithm for pricing variable annuities with GLWB under a stochastic mortality framework. Although our set-up is very general and only requires the Markovian property for the mortality intensity and the asset price processes, in the numerical implementation of the algorithm we model the former as a non mean reverting square root process, and the latter as an exponential Lévy process. In this way we get a tractable and flexible stochastic model for efficient pricing and risk management of the GLWB. Another contribution of our paper is the verification, through backward induction, of the bang-bang condition for the set of discrete withdrawal strategies of the model. This result is particularly remarkable as in the insurance literature either the existence of optimal bang-bang controls is assumed or it requires suitable conditions. We present extensive numerical examples and compare the results obtained for different market parameters and policyholder behaviours.