Source: https://www.irit.fr/~Martin.Strecker/Teaching/2004/L2_S4_Programmation_Imperative/TD/TD3_sous_prog.pdf